![]() |
|
Just another Perl shrine | |
PerlMonks |
Re^2: search for particular elements of hash with multiple valuesby marioroy (Parson) |
on Apr 20, 2017 at 21:54 UTC ( #1188488=note: print w/replies, xml ) | Need Help?? |
Update: This post was made to showcase another way to benchmark when involving parallel workers. Upon further review, the OP's post wants to increment $bc_pair_num which isn't done here. I will come back later and update the code. Also, sorting is not required when Perl has two fast ordered-hash implementations. I will try Hash::Ordered and MCE::Shared::Ordhash (constructed as non-shared). These modules are fast. Update: The OP does not mention sorting. Therefore please disregard the mentioning of the two ordered-hash implementations. Like haukex said, sorting is helpful during debugging sessions. This is true. Update: Posted a non-benchmark version, which increments the $bc_pair_num field. Greetings, Sometimes workers may not stop immediately like you want them to with various benchmark modules. The following is another way, based on karlgoethebier's example. For an array (mce_loop), the manager process chunks and sends the next chunk via IPC. For sequence (mce_loop_s) and with the bounds_only option, workers compute the next offset begin and end boundaries. Thus, runs with lesser overhead. If you must set the chunk_size option, do not go over 8000 when processing an array. Perl performance degrades if you go higher. Better yet, simply comment out the chunk_size option or not set it. There's no easy formula for setting chunk_size. However, the default chunk_size => 'auto' for MCE Models do a good job for most cases. For arrays, check to see if Perl has Sereal::Decoder and Sereal::Encoder 3.015 or later installed. MCE will use Sereal 3.015+ for serialization if available. Otherwise, it defaults to Storable. The results are mind-boggling. The reason is that for arrays, MCE involves the manager process which chunks the array elements and sends via IPC. Even with that overhead, MCE runs faster. That requires the our vs my keyword on %barcode_hash and $barcode_pair_35. Thank you, karlgoethebier for this enlightenment. Results: run 50 times for 100000 keys: $max set to 1e5.
Results: run 50 times for 1 million keys: $max set to 1e6.
Demo script.
For the MCE bits, I used MCE->gather and MCE->abort. The abort method is helpful which stops all workers from processing more chunks. Thus, ending the job early. Update: Results from a Windows 7 VM configured with 4 cores and Strawberry Perl. I think Perl makes extra copies. Thus, involves extra time during spawning. Results: run 50 times for 100000 keys: $max set to 1e5.
Results: run 50 times for 1 million keys: $max set to 1e6.
Update: Also tested Perl from the Cygwin environment. Here, it seems workers are spawned instantly after the initial creation. This is see via the task manager. Results: run 50 times for 100000 keys: $max set to 1e5.
Results: run 50 times for 1 million keys: $max set to 1e6.
Regards, Mario.
In Section
Seekers of Perl Wisdom
|
|