Rate brute_force mwah grinder
brute_force 125/s -- -25% -92%
mwah 167/s 33% -- -89%
grinder 1520/s 1114% 812% --
####
Rate mwah brute_force grinder
mwah 156/s -- -32% -87%
brute_force 229/s 47% -- -81%
grinder 1181/s 659% 416% --
####
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(:all);
my $grinder = sub {
for (0 .. 1000){
if ("$_" =~ m/^(?:2(?:[6-9]|5[0-5]?|[0-4]\d?)?|[3-9]\d?|1(?:\d\d?)?|0)$/){
if ($_ > 255){
print "Fails for $_\n";
}
} else {
if ($_ < 255){
print "Fails for $_\n";
}
}
}
};
my $mwah = sub {
my $re = qr{
((?>\d+)) # what to capture, don't backtrack: (+?> )
(??{
$1<255 # what is looked for
? '' # if yes, let the regex succeed
: '(?!)' # if no, let the regex bail
})
}x;
for (0 .. 1000){
if ("$_" =~ m/^$re$/){
if ($_ > 255){
print "Fails for $_\n";
}
} else {
if ($_ < 255){
print "Fails for $_\n";
}
}
}
};
my $bruteforce = sub {
my $re = join '|', 0 .. 255;
# print $re, "\n";
for (0 .. 1000){
if ("$_" =~ m{^(?:$re)$}){
if ($_ > 255){
print "Brute force Fails for $_\n";
}
} else {
if ($_ < 255){
print "Brute force Fails for $_\n";
}
}
}
};
cmpthese(-3, {
grinder => $grinder,
mwah => $mwah,
brute_force => $bruteforce,
});