![]() |
|
Just another Perl shrine | |
PerlMonks |
Re: Speed comparison of foreach vs grep + mapby ikegami (Patriarch) |
on May 25, 2025 at 18:28 UTC ( [id://11165116]=note: print w/replies, xml ) | Need Help?? |
As Corion pointed out, the switch from !$_ to /0/ is overpowering the other differences and invalidating your test. But other improvements can be made. There's no reason to use an intermediate array in the latter snippet. This avoids the creation of 5 million scalars.
You could even eliminate the grep.
Similar improvements can be made for the foreach version.
Finally, I'm curious how these compare:
In Section
Seekers of Perl Wisdom
|
|