# THIS doesnt mean \\server_name\sys_share it means \server_name\sys_share
$unc = '\\server_name\sys_share';
# and then you remove the leading "\" and trailing "\sys_share" before the benchmark even starts!
$unc =~ s/^\W*\w+//;
$server = $&;
$server =~ s/^\W+//;
# None of the regexes in the benchmark will match anymore (in a meaningful way)
####
#!perl
use warnings;
use Benchmark;
$unc = '\\\\server_name\\sys_share';
my $re = Benchmark::timethese(-5,
{
blackadder => sub {
$lunc = $unc;
$lunc =~ s/^\W*\w+//;
$server = $&;
$server =~ s/^\W+//;
},
theorbtwo => sub {
$unc =~ m/^\\\\([^\\]+)\\/;
$server = $1;
}
}
);
Benchmark::cmpthese($re);
__END__
Benchmark: running blackadder, theorbtwo, each for at least 5 CPU seconds...
blackadder: 6 wallclock secs ( 5.12 usr + 0.00 sys = 5.12 CPU) @ 131371.90/s (n=673281)
theorbtwo: 5 wallclock secs ( 5.34 usr + 0.00 sys = 5.34 CPU) @ 190423.65/s (n=1017624)
Rate blackadder theorbtwo
blackadder 131372/s -- -31%
theorbtwo 190424/s 45% --
####
# benchmark saw ampersand -- BlackAdder
use strict;
use warnings;
use Benchmark qw(timethis);
use Data::Dumper;
my $count=$ARGV[0] || -1;
my $unc =$ARGV[1] || '\\\\server_name\\sys_share';
print "Matching $unc for $count\n";
print Dumper(timethis($count,sub {
my $lunc = $unc;
$lunc =~ s/^\W*\w+//;
(my $server = $&)=~ s/^\W+//;
$server
},'blackadder'
));
####
# benchmark saw ampersand -- theorbtwo
use strict;
use warnings;
use Benchmark qw(timethis);
use Data::Dumper;
my $count=$ARGV[0] || -1;
my $unc =$ARGV[1] || '\\\\server_name\\sys_share';
print "Matching $unc for $count\n";
print Dumper(timethis($count,sub {
$unc =~ m/^\\\\([^\\]+)\\/;
$1;
}, 'theorbtwo'
));
####
use Benchmark 'cmpthese';
use Data::Dumper;
sub run_bm($){
my $str=shift;
my $h;
$str=~s/\A(.*)\$VAR1 =/$h=$1;''/se;
print $h;
my $v=eval($str);
die $@ if $@;
$v
}
my $opts='-5 \\\\foo\\bar\\baz.exe;
my $hash={
blackadder => run_bm(`perl bm_blackadder.pl $opts`),
theorbtwo => run_bm(`perl bm_theorbtwo.pl $opts`),
};
cmpthese($hash);
__END__
####
Matching \\foo\bar\baz.exe for -5
blackadder: 6 wallclock secs ( 5.22 usr + 0.00 sys = 5.22 CPU) @ 135204.60/s (n=705768)
Matching \\foo\bar\baz.exe for -5
theorbtwo: 6 wallclock secs ( 5.17 usr + 0.00 sys = 5.17 CPU) @ 367160.48/s (n=1898954)
Rate blackadder theorbtwo
blackadder 135205/s -- -63%
theorbtwo 367160/s 172% --