There's more than one way to do things | |
PerlMonks |
Re^2: Using foreach to process a hashby jdporter (Paladin) |
on Oct 22, 2006 at 14:06 UTC ( [id://579859]=note: print w/replies, xml ) | Need Help?? |
Unfortunately, DigitalKitty's benchmark suffers from a couple of major flaws. Primarily, the subs under test are doing prints. That means that timing is going to be swamped by I/O. The second thing is that the hash is so small, that in the ops performed by each sub, the ones we're trying to test (each and keys) occur very few times, relative to the overhead of calling the sub, etc. So I offer the following benchmark, which eliminates both of those sources of error.
Output: (slightly edited)
As you can see, for large hashes, while each wins over for keys. And you also gain a little by using the default iterator on the for loop.
We're building the house of the future together.
In Section
Seekers of Perl Wisdom
|
|