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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Concatenate or Join?
by perldaemon (Novice) on Nov 13, 2012 at 00:43 UTC | |
by dave_the_m (Monsignor) on Nov 13, 2012 at 09:11 UTC |
In Section
Seekers of Perl Wisdom