$var = "foo" ;
$var .= "bar" ; # 1
$var = "foo$var" ; # 2
substr($var,0,0) = "foo" ; # 3
####
#!/usr/bin/perl -w
use Benchmark;
timethese(1_500_000, {
Interpolate => q/$var = "String"; $var = "foo$var";/,
Concatenate => q/$var = "String"; $var = "foo" . $var;/,
Substr => q/$var = "String"; substr($var, 0, 0) = 'foo'/
});
##
##
Benchmark: timing 1500000 iterations of Concatenate, Interpolate, Substr...
Concatenate: 1 wallclock secs ( 1.56 usr + 0.00 sys = 1.56 CPU) @ 960000.00/s (n=1500000)
Interpolate: 1 wallclock secs ( 1.59 usr + 0.00 sys = 1.59 CPU) @ 945812.81/s (n=1500000)
Substr: 2 wallclock secs ( 2.07 usr + 0.01 sys = 2.08 CPU) @ 721804.51/s (n=1500000)