in reply to
Concatenate or Join?
You are not comparing concat against join. You are comparing
concat against creating and repeatedly extending an array and joining.
With a level playing field, join is quicker:
use Benchmark;
my @a = ('x') x 1_000_000;
timethese(100, {
'concat' => sub { my $s; $s .= $_ for @a },
'join' => sub { my $s = join '', @a },
},);
__END__
concat: 11 wallclock secs (10.86 usr + 0.01 sys = 10.87 CPU) @ 9
+.20/s (n=100)
join: 4 wallclock secs ( 4.01 usr + 0.00 sys = 4.01 CPU) @ 24
+.94/s (n=100)
Dave.