Skip to content

Commit

Permalink
Add benchmark script
Browse files Browse the repository at this point in the history
This was used to optimise newick parsing.
  • Loading branch information
shawnlaffan committed Jul 10, 2022
1 parent e815888 commit a97cfc3
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions etc/benchmark_scripts/bench_regex_oflag.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use 5.016;
use warnings;
use Benchmark qw {:all};

#use Data::Dumper;
use Regexp::Common qw /number delimited/;

use constant CONST_RE_NUMCAPTURE => qr /\G ($RE{num}{real})/xmso;

my $RE_NUMBER = qr /$RE{num}{real}/xmso;
my $RE_QUOTED = qr /$RE{delimited}{-delim=>"'"}{-esc=>"'"}/o;

my $RE_NUM_CAPTURE = qr /\G ( $RE_NUMBER ) /xs;

my $string = '12335567j';

cmpthese (
-5,
{
orig => sub {orig ()},
oflag => sub {oflag()},
qcapt => sub {qcapt()},
qcapo => sub {qcapto()},
ccapo => sub {ccapto()},
},
);



sub orig {
for (1..10000) {
$string =~ m/\G ( $RE_NUMBER ) /xgcs;
}
}

sub oflag {
for (1..10000) {
$string =~ m/\G ( $RE_NUMBER ) /xgcso;
}
}

sub qcapt {
for (1..10000) {
$string =~ m/$RE_NUM_CAPTURE/gc;
}
}

sub qcapto {
for (1..10000) {
$string =~ m/$RE_NUM_CAPTURE/gco;
}
}

sub ccapto {
for (1..10000) {
$string =~ m/${\CONST_RE_NUMCAPTURE()}/gc;
}
}

0 comments on commit a97cfc3

Please sign in to comment.