Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: search for particular elements of hash with multiple values

by marioroy (Prior)
on Apr 20, 2017 at 23:32 UTC ( [id://1188498]=note: print w/replies, xml ) Need Help??


in reply to Re^2: search for particular elements of hash with multiple values
in thread search for particular elements of hash with multiple values

To display the location, I changed the code accordingly and run 1 time. Running serially seems fast enough. Basically, Perl completes in less than 1 second for 1 million keys from an Intel i7 Haswell chip running at 2.6 GHz. Nethertheless, this post was written to demonstrate workers sending data to the manager-process for STDOUT via MCE->print(...).

Results: run 1 and 2 times for 1 million keys: $max set to 1e6.

$ perl demo2.pl haukex 1 Found at 999999 Found at 1000000 duration (haukex): 0.336 seconds $ perl demo2.pl karlary 1 Found at 999999 Found at 1000000 duration (karlary): 0.231 seconds $ perl demo2.pl karlseq 1 Found at 999999 Found at 1000000 duration (karlseq): 0.122 seconds
$ perl demo2.pl haukex 2 Found at 999999 Found at 1000000 Found at 999999 Found at 1000000 duration (haukex): 0.665 seconds $ perl demo2.pl karlary 2 Found at 999999 Found at 1000000 Found at 999999 Found at 1000000 duration (karlary): 0.477 seconds $ perl demo2.pl karlseq 2 Found at 999999 Found at 1000000 Found at 999999 Found at 1000000 duration (karlseq): 0.253 seconds

Below, workers report the location.

... { no strict 'refs'; my $start = time; $func->() for 1 .. $count; printf "duration ($func): %0.03f seconds\n", time - $start; } ... sub haukex { # serial code for my $key ( 1 .. $max ) { print "Found at $key\n" if ( $barcode_hash{$key}[2] eq $barcode_pair_35 ); } return; } sub karlary { # workers receive next array chunk mce_loop { my ( $mce, $chunk_ref, $chunk_id ) = @_; for my $key ( @$chunk_ref ) { MCE->print("Found at $key\n") if ( $barcode_hash{$key}[2] eq $barcode_pair_35 ); } } 1 .. $max; # <-- for array 1 .. $max return; } sub karlseq { # workers receive next sequence 'begin' and 'end' boundaries mce_loop_s { my ( $mce, $chunk_ref, $chunk_id ) = @_; for my $key ( $chunk_ref->[0] .. $chunk_ref->[1] ) { MCE->print("Found at $key\n") if ( $barcode_hash{$key}[2] eq $barcode_pair_35 ); } } 1, $max; # <-- for sequence 1, $max return; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-23 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found