Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by admiral_grinder (Pilgrim)
on Nov 20, 2008 at 21:13 UTC ( [id://724992]=note: print w/replies, xml ) Need Help??


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

I remember one time getting a noticeable speed improvement by using the 'for (...;...;...)' over a foreach loop for a large array. I wondering if that would have helped here.
  • Comment on Re^3: Fast, Efficient Union and Intersection on arrays

Replies are listed 'Best First'.
Re^4: Fast, Efficient Union and Intersection on arrays
by TGI (Parson) on Nov 20, 2008 at 22:22 UTC

    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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found