From a97cfc38122607ae98c1731b2583379919593c65 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Sun, 10 Jul 2022 17:07:34 +1000 Subject: [PATCH] Add benchmark script This was used to optimise newick parsing. --- etc/benchmark_scripts/bench_regex_oflag.pl | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 etc/benchmark_scripts/bench_regex_oflag.pl diff --git a/etc/benchmark_scripts/bench_regex_oflag.pl b/etc/benchmark_scripts/bench_regex_oflag.pl new file mode 100644 index 000000000..ab63f5687 --- /dev/null +++ b/etc/benchmark_scripts/bench_regex_oflag.pl @@ -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; + } +}