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

(warning: too few iterations for a reliable count)

You can get rid of those warnings by increasing the runtime by saying e.g. cmpthese(-5, .... I did fiddle with it quite a bit, adjusting the string length, runtime, etc. and the results were always consistent that split was fastest by a significant margin.

Replies are listed 'Best First'.
Re^3: Is foreach split Optimized?
by Marshall (Canon) on Jul 09, 2017 at 11:57 UTC
    Interesting:
    5.020002 Rate index regex split split2 index 1.17/s -- -23% -35% -43% regex 1.51/s 29% -- -16% -26% split 1.79/s 53% 18% -- -12% split2 2.03/s 74% 35% 14% --
    split2 uses tr/// instead of regex s///...

      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;.

        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% --