Perl-Sensitive Sunglasses | |
PerlMonks |
Re^2: map {} list or do {} for list? - Benchmarksby davido (Cardinal) |
on Apr 12, 2014 at 17:53 UTC ( [id://1082109]=note: print w/replies, xml ) | Need Help?? |
When you see operations per second that high, you should ask yourself if any work is being done. In fact, none really is, and your benchmark is rendered totally unreliable as a result. First, you have scoping issues. And even if you fix those, you remain with the issue that choroba identified; that the first benchmark iteration deletes from the master copy of the hash, leaving remaining iterations with less work to do. Here's a version that codes around the scoping issues that evaled code creates, and that makes a copy of %hosts on each iteration. That copy costs time, but it costs the same amount of time for each snippet.
And here's the output I get:
"nada" is just there to identify how much time we're wasting making a fresh copy of the hash on each iteration. As you can see, all of the approaches except for the copy one are so close that they're probably within the margin of error. Use the one that seems most legible, and if there's a risk that it won't be comprehended, encapsulate by wrapping it in a well-named subroutine. Dave
In Section
Seekers of Perl Wisdom
|
|