Keep It Simple, Stupid | |
PerlMonks |
Re^5: better array to hash conversionby tobyink (Canon) |
on Dec 11, 2012 at 16:24 UTC ( [id://1008335]=note: print w/replies, xml ) | Need Help?? |
The following map variant works out significantly faster than the previously posted map variants, though not as fast as for-loop based variants:
While the block form of map is often favoured for its clarity, the expression form of map is faster because it avoids the overhead of creating a lexical pad. This is actually another reason why BrowserUk's variation4 is fast - he uses the for statement modifier rather than a for loop with a block. Compare:
Yes, it's a small difference, but it's pretty consistently observable. The absolute fastest I've been able to achieve is a small variation on BrowserUk's variation4 using the prefix increment rather than postfix increment:
It seems to give you about a 6% speed up.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
In Section
Seekers of Perl Wisdom
|
|