Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

RE: Re: each or keys?

by rdw (Curate)
on Oct 11, 2000 at 11:05 UTC ( #36189=note: print w/replies, xml ) Need Help??

in reply to Re: each or keys?
in thread each or keys?

Doh! You're right of course, how silly not to notice it before - the break out test is completely stupid. (I guess in the back of my mind I must have thought the values were coming out in order - which of course they are not). It breaks out very early and that explains why it's so much faster.

If I change the test to >400000 (which gets me about 3/4 through the hash) then I get the following results...

Benchmark: timing 1000 iterations of each, keys...
      each:  2 wallclock secs ( 2.39 usr +  0.00 sys =  2.39 CPU) @ 418.41/s (n=1000)
      keys:  2 wallclock secs ( 2.23 usr +  0.00 sys =  2.23 CPU) @ 448.43/s (n=1000)
      Rate each keys
each 418/s   --  -7%
keys 448/s   7%   -- it looks like keys generally wins - because of the 'random' order that things come out, you can't tell how soon a loop test break you out of the loop.

Thanks tilly


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-04-13 07:06 GMT
Find Nodes?
    Voting Booth?

    No recent polls found