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% --
...so 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
rdw
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|