in reply to Optimizing Output

Doesn't it say somewhere that interpolating is faster than multiple .'s? If I remember correctly, each '.' forces a copy, where as interpolation only does it once.

$string .= $a . $b . $c . $d;

does like 5 copies, whereas

$string = "$string$a$b$c$d";

only does one.

Because of this, I always do interpolation if I can, but I won't go out of my way to do so.

Replies are listed 'Best First'.
Re: Re: Optimizing Output
by sfink (Deacon) on Apr 15, 2002 at 20:35 UTC
    No.
    perl -Dt -e '"$a$b".$c.$d' EXECUTING... (-e:0) enter (-e:0) nextstate (-e:1) gvsv(main::a) (-e:1) gvsv(main::b) (-e:1) concat (-e:1) gvsv(main::c) (-e:1) concat (-e:1) gvsv(main::d) (-e:1) concat (-e:1) leave
    They both call the concat opcode.

    At one time, I remember the tokenizer actually rewrote "x$y" to be "x" . $y and "recursed" on it. But it doesn't seem to anymore. O::Deparse can even tell the difference:

    perl -MO=Deparse -e '"$a$b".$c.$d' "$a$b" . $c . $d;