On Thu, 18 May 2000, brian moseley wrote:
> On Thu, 18 May 2000, Jeffrey W. Baker wrote:
>
> > .= concatenation is way faster
>
> i don't have any results to back up my claim. therefore,
> my words are eaten :)
>
> i was convinced tho, even way back before you came to cp. i
> wonder what convinced me!
that was probably me :) but, i don't recall suggesting join.
but i do recall pushing away from concat when print()-ing, this benchmark
also illustrates why i made Apache::print dereference references to
strings. 5.005_03 does seem todo better with the array benchmark than
5.006, oh well. there's tradeoffs both ways, i don't think there's a
clear winner.
Benchmark: timing 30000 iterations of array, concat, ref_array...
array: 8 wallclock secs ( 6.90 usr + 0.27 sys = 7.17 CPU) @4184.10/s (n=30000)
concat: 7 wallclock secs ( 5.98 usr + 0.16 sys = 6.14 CPU) @4885.99/s (n=30000)
ref_array: 5 wallclock secs ( 4.59 usr + 0.16 sys = 4.75 CPU) @6315.79/s (n=30000)
use Benchmark;
open my $fh, ">/dev/null" or die;
my($one, $two, $three) = map { $_ x 4096 } 'a'..'c';
timethese(30_000, {
'ref_array' => sub {
my @a;
push @a, \($one, $two, $three);
my_print(@a);
},
'array' => sub {
my @a;
push @a, $one, $two, $three;
my_print(@a);
},
'concat' => sub {
my $s;
$s .= $one;
$s .= $two;
$s .= $three;
my_print($s);
},
});
sub my_print {
for (@_) {
print $fh ref($_) ? $$_ : $_;
}
}