in reply to Re: String Concatenation Performance
in thread String Concatenation Performance

Thank you - this is excellent. You have confirmed my suspicion that my tests were not good. Now I need to find a test that tricks the optimizer. Given that the ex-stringify sK/1 ->a op was removed, I guess using constant strings is not the way to test.

I always understood that 'abc' was better than "abc", because of the interpolation, but it seems that the optimizer sees through this, given the constant strings, so all I am doing is being kinder to the optimizer. Premature optimization.

The following now uses a string read from <>, and therefore not a constant:

% perl -MO=Concise my $s=<>; my $t="$s"; b <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -:1) v ->3 - <1> null vKS/2 ->6 3 <0> padsv[$s:1,3] sRM*/LVINTRO ->4 5 <1> readline[t3] sKS/1 ->6 4 <#> gv[*ARGV] s ->5 6 <;> nextstate(main 2 -:2) v ->7 a <2> sassign vKS/2 ->b 8 <@> stringify[t5] sK/1 ->9 - <0> ex-pushmark s ->7 7 <0> padsv[$s:1,3] s ->8 9 <0> padsv[$t:2,3] sRM*/LVINTRO ->a
I'll recreate tests based on this. Thank you all.

Replies are listed 'Best First'.
Re^3: String Concatenation Performance
by Aristotle (Chancellor) on Mar 20, 2004 at 18:24 UTC
    The following now uses a string read from <>, and therefore not a constant:
    Your assumptions about what happens why are incorrect.
    $ perl -MO=Concise -e'my $s=""; my $t="$s";' b <@> leave&#91;$s:1,3] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 3 <$> const(PV "") s ->4 4 <0> padsv[$s:1,3] sRM*/LVINTRO ->5 6 <;> nextstate(main 2 -e:1) v ->7 a <2> sassign vKS/2 ->b 8 <@> stringify[t3] sK/1 ->9 - <0> ex-pushmark s ->7 7 <0> padsv[$s:1,3] s ->8 9 <0> padsv[$t:2,3] sRM*/LVINTRO ->a -e syntax OK
    The "stringify" op is still active.

    Makeshifts last the longest.