in reply to Re^3: Is foreach split Optimized?
in thread Is foreach split Optimized? (Update: No.)

I'm investigating the speed of iterating through the string, not how it gets processed afterwards, which is why the loop bodies are all the same. So to make the benchmark be fair again, you'd have to make the same change in all the loops. I just added that bit of s/// code to provide a somewhat realistic loop body (Update: or rather, a placeholder for the actual loop body, which manipulates the $line a whole lot more and whose output is much more complex than one line of output per line of input), and as a (likely misguided) attempt to prevent for my $line (@x) { push @lines, $line; } from being optimized to @lines = @x;.

Replies are listed 'Best First'.
Re^5: Is foreach split Optimized?
by Marshall (Canon) on Jul 09, 2017 at 13:02 UTC
    Fair enough. With that change for more "apples to apples"..
    5.020002 Rate index regex split2 index 1.27/s -- -19% -34% regex 1.57/s 23% -- -19% split2 1.93/s 52% 23% --