3 ms·
One example I can think of is this: if you write perl using 'canonical' expressions, your code will often get compiled to optimized function calls. But if you u
by DougWebb 8y ago
One example I can think of is this: if you write perl using 'canonical' expressions, your code will often get compiled to optimized function calls. But if you use non-canonical expressions to perform the same operation, the compiled code won't be optimized and will run a lot slower.
An example would be using a map expression instead of a for loop. The map expression will typically run faster, even though its body is pretty much the same as the for loop's body.
- lizmat 8y agoFWIW, in Perl 6 there is no real difference between a `map` and a `for` loop: in the case of the `for` loop, the final value of each iteration is simply discarded.
- rurban 8y agoNo. map should be much slower than a for loop, because map has to cons the result list, while the for loop only does it for side effects, but ignores all the return values. If map is faster, then there's some thing wrong with the loop optimizer or loop run-time overhead. In cperl there are many loop optimizations which are not in perl5. I'm pretty sure "for" is faster than "map" there.