in reply to String concatenation
This is probably a case of unnecessary optimization, but here are benchmark results for those interested:
s/iter join dot interpolate1 interpolate +2 join 2.22 -- -24% -25% -32 +% dot 1.69 31% -- -1% -11 +% interpolate1 1.67 33% 1% -- -10 +% interpolate2 1.50 48% 13% 12% - +-
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.
use strict; use warnings; use Benchmark qw/:all/; my $string; my ($var1, $var2, $var3) = ('asdf', 'zxcv', 'qwer'); cmpthese(4, { dot => sub { $string = $var1 . $var2 . $var3 for (0 .. 10000000); }, interpolate1 => sub { $string = "${var1}${var2}${var3}" for (0 .. 10000000); }, interpolate2 => sub { $string = "$var1$var2$var3" for (0 .. 10000000); }, join => sub { $string = join('', $var1, $var2, $var3) for (0 .. 10000000); }, });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: String concatenation
by chromatic (Archbishop) on Apr 11, 2012 at 20:31 UTC | |
by dave_the_m (Monsignor) on Apr 11, 2012 at 20:57 UTC | |
by JavaFan (Canon) on Apr 11, 2012 at 21:22 UTC | |
by Eliya (Vicar) on Apr 11, 2012 at 21:35 UTC | |
by Riales (Hermit) on Apr 11, 2012 at 20:37 UTC | |
by JavaFan (Canon) on Apr 11, 2012 at 21:26 UTC |