Thanks, that looks like a much more compelling benchmark. I can well imagine Paul Evans seeing the first two benchmarks and being inspired to make List::Util::all (and related functions) competitive with for for the "first: 0" case. But hopefully not before completing the perl release that's due soon. :)
I believe the special handling of for (@array) is switched in by the peephole optimizer; I'm not sure whether that means it would need a new op for each of the relevant List::Util functions or whether adding one just for reduce() would be sufficient.
I'd recommend posting that benchmark (without the "chaining" section) as part of a feature request something like "make List::Util functions as fast as 'for (@array)'" in github.
The "chaining" example is another matter: I think solving that would need something a lot closer to the generalized "lazy evaluation" I mentioned before. It may be worth asking about that too, but I'd suggest doing so in a separate ticket to avoid muddying the waters.
In reply to Re^2: The Virtue of Laziness
by hv
in thread The Virtue of Laziness
by jo37
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |