Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Fast, Efficient Union and Intersection on arrays

by TGI (Vicar)
on Nov 20, 2008 at 22:22 UTC ( #725005=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Fast, Efficient Union and Intersection on arrays
in thread Fast, Efficient Union and Intersection on arrays

Once again, expectations are shattered: the c style for loop is the slowest.

sub one_cfor { # my (@a, @b); # initialize @a and @b here my %hash; @hash{@a} = (1) x @a; my @union = @a; my @intersection; for (my $i=0; $i<$#b; $i++ ) { my $bval = $b[$i]; if( exists $hash{$bval} ) { push @intersection, $bval } else { push @union, $bval } } # print "union @union\n"; # print "interstection @intersection\n"; } ################ Range (1,50) vs (3,80) Rate one_cfor one_for two_greps one_cfor 4438/s -- -24% -30% one_for 5834/s 31% -- -8% two_greps 6312/s 42% 8% -- Range (1,5) vs (3,8) Rate one_cfor one_for two_greps one_cfor 50000/s -- -13% -29% one_for 57637/s 15% -- -18% two_greps 70323/s 41% 22% --


TGI says moo


Comment on Re^4: Fast, Efficient Union and Intersection on arrays
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2015-07-02 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (33 votes), past polls