c:\test>\perl\bin\perl5.8.6.exe -s junk9.pl -N=1e2
Rate ysth buk tye OP
ysth 4371/s -- -47% -49% -75%
buk 8269/s 89% -- -3% -53%
tye 8542/s 95% 3% -- -52%
OP 17779/s 307% 115% 108% --
c:\test>\perl\bin\perl5.8.6.exe -s junk9.pl -N=1e5
Rate ysth buk tye OP
ysth 3.75/s -- -36% -39% -64%
buk 5.88/s 57% -- -4% -44%
tye 6.15/s 64% 5% -- -41%
OP 10.5/s 179% 78% 70% --
####
c:\test>\Perl510\bin\perl5.10.0.exe -s junk9.pl -N=1e2
Rate ysth tye OP buk
ysth 2326/s -- -50% -64% -72%
tye 4670/s 101% -- -27% -45%
OP 6417/s 176% 37% -- -24%
buk 8419/s 262% 80% 31% --
c:\test>\Perl510\bin\perl5.10.0.exe -s junk9.pl -N=1e5
Rate ysth OP tye buk
ysth 1.83/s -- -32% -46% -69%
OP 2.70/s 48% -- -21% -55%
tye 3.42/s 87% 26% -- -43%
buk 5.98/s 227% 121% 75% --
c:\test>\Perl510\bin\perl5.10.0.exe -s junk9.pl -N=1e6
s/iter OP ysth tye buk
OP 43.0 -- -54% -60% -96%
ysth 19.9 116% -- -14% -91%
tye 17.1 151% 16% -- -90%
buk 1.72 2400% 1056% 896% --
####
#! perl -slw
use strict;
use Benchmark qw[ cmpthese ];
my %subst = ( '&' => 'amp', '>' => 'gt', '<' => 'lt' );
our $ysth = join('|', map quotemeta, sort { length($b) <=> length($a) || $b cmp $a } keys %subst);
our $N ||= 1e3;
our $data = join( '', map{ 'junk ' . (qw[ & < > ])[ rand 3 ] } 1 .. $N );
cmpthese -3, {
OP => sub {
$_ = $data;
s{\&}{amp}g;
s{\<}{lt}g;
s{\>}{gt}g
},
tye => sub {
$_ = $data;
s{([&<>])}{$subst{$1}}ge;
},
ysth => sub {
$_ = $data;
s{($ysth)}{$subst{$1}}ge;
},
buk => sub {
$_ = $data . ' ';
$_ = join 'amp', split '&';
$_ = join 'lt', split '<';
$_ = join 'gt', split '>';
chop;
},
};