Я сделал тест!:)
#!/usr/bin/perl
use warnings;
use strict;
use Benchmark qw(cmpthese timethese);
my $bench = timethese($ARGV[1], {
multi_concat => sub {
my $string = "Hi, I am a very long and chatty string that just won't";
$string .= " quit. I'm going to keep going, and going, and going,";
$string .= " kind of like the Energizer bunny. What are you going to";
$string .= " do about it?";
},
one_concat => sub {
my $string = "Hi, I am a very long and chatty string that just won't" .
" quit. I'm going to keep going, and going, and going," .
" kind of like the Energizer bunny. What are you going to" .
" do about it?";
},
join => sub {
my $string = join("", "Hi, I am a very long and chatty string that just won't",
" quit. I'm going to keep going, and going, and going,",
" kind of like the Energizer bunny. What are you going to",
" do about it?"
);
},
} );
cmpthese $bench;
1;
Результаты (на моем iMac с Perl 5.8.9):
imac:Benchmarks seb$ ./strings.pl 1000
Benchmark: running join, multi_concat, one_concat for at least 3 CPU seconds...
join: 2 wallclock secs ( 3.13 usr + 0.01 sys = 3.14 CPU) @ 3235869.43/s (n=10160630)
multi_concat: 3 wallclock secs ( 3.20 usr + -0.01 sys = 3.19 CPU) @ 3094491.85/s (n=9871429)
one_concat: 2 wallclock secs ( 3.43 usr + 0.01 sys = 3.44 CPU) @ 12602343.60/s (n=43352062)
Rate multi_concat join one_concat
multi_concat 3094492/s -- -4% -75%
join 3235869/s 5% -- -74%
one_concat 12602344/s 307% 289% --