Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: map vs for\foreach. (perf)by tye (Sage) |
on Mar 11, 2015 at 15:49 UTC ( [id://1119661]=note: print w/replies, xml ) | Need Help?? |
Picking your syntax based on benchmarks of trivial operations is total folly. Use map if you want to get back a list. Don't otherwise. Now, there can be non-trivial performance implications in similar syntax choices between for() and while() when reading from a (large) file, for example. But you also likely would not discover those from running benchmarks of trivial operations. The benchmark results presented so far mostly illustrate differences in the trivial operations being done, not any performance difference that is likely to actually matter if you were changing useful code between map/for() [for cases of code where for() made sense]. - tye
In Section
Seekers of Perl Wisdom
|
|