<?xml version="1.0" encoding="windows-1252"?>
<node id="964615" title="Re: String concatenation" created="2012-04-11 16:21:23" updated="2012-04-11 16:21:23">
<type id="11">
note</type>
<author id="892462">
Riales</author>
<data>
<field name="doctext">
&lt;p&gt;This is probably a case of unnecessary optimization, but here are benchmark results for those interested:&lt;/p&gt;

&lt;code&gt;
             s/iter         join          dot interpolate1 interpolate2
join           2.22           --         -24%         -25%         -32%
dot            1.69          31%           --          -1%         -11%
interpolate1   1.67          33%           1%           --         -10%
interpolate2   1.50          48%          13%          12%           --
&lt;/code&gt;

&lt;p&gt;And here's the code that generated this. I had to loop a bunch to get any kind of result. Not sure if this has any kind of effect on anything.&lt;/p&gt;

&lt;code&gt;
use strict;
use warnings;

use Benchmark qw/:all/;

my $string;

my ($var1, $var2, $var3) = ('asdf', 'zxcv', 'qwer');

cmpthese(4, {
    dot =&gt; sub {
        $string = $var1 . $var2 . $var3 for (0 .. 10000000);
    },  
    interpolate1 =&gt; sub {
        $string = "${var1}${var2}${var3}" for (0 .. 10000000);
    },  
    interpolate2 =&gt; sub {
        $string = "$var1$var2$var3" for (0 .. 10000000);
    },  
    join =&gt; sub {
        $string = join('', $var1, $var2, $var3) for (0 .. 10000000);
    },  
});
&lt;/code&gt;</field>
<field name="root_node">
964608</field>
<field name="parent_node">
964608</field>
</data>
</node>
