Rate Without /o With /o With qr
Without /o 42725/s -- -26% -39%
With /o 57636/s 35% -- -18%
With qr 70185/s 64% 22% --
####
Rate 2// 2/o 1// 1/o 1qr 2qr
2// 31.4/s -- -0% -0% -1% -25% -26%
2/o 31.5/s 0% -- -0% -0% -25% -25%
1// 31.6/s 0% 0% -- -0% -25% -25%
1/o 31.6/s 1% 0% 0% -- -25% -25%
1qr 41.9/s 33% 33% 33% 33% -- -1%
2qr 42.2/s 34% 34% 34% 34% 1% --
##
##
Without /o:2200
With /o:2200
With qr:2200
##
##
#!/usr/bin/perl -w
use strict;
use Benchmark qw( cmpthese );
chomp( my @words = );
push @words, map $_ x 100, @words;
for( @words ) {
if( s/ /0/g ) {
s/0/ /;
$_= reverse $_;
}
}
seek DATA, 0, 0;
push @words, grep chomp, ;
@words= ( @words ) x 100;
my $alpha = '[a-zA-Z]';
my $alnum = '[a-zA-Z0-9]';
my $qr= qr/^$alpha$alnum+$/;
print
'Without /o:' => testsub(), $/,
'With /o:' => testsubo(), $/,
'With qr:' => testsubqr(), $/;
cmpthese( -3, {
'1//' => \&testsub,
'1/o' => \&testsubo,
'1qr' => \&testsubqr,
'2//' => \&testsub,
'2/o' => \&testsubo,
'2qr' => \&testsubqr,
});
sub testsub {
my $count = 0;
foreach (@words) {
$count++ if(/^$alpha$alnum+$/);
}
return $count;
}
sub testsubo {
my $count = 0;
foreach (@words) {
$count++ if(/^$alpha$alnum+$/o);
}
return $count;
}
sub testsubqr {
my $count = 0;
foreach (@words) {
$count++ if $_ =~ $qr;
}
return $count;
}
__DATA__
include
the real
test
data
or code
to generate
it
when
posting
benchmarks