Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why do these 2 RegEx benchmarks differ so much?
- # Benchmark
- use Benchmark qw(:all);
- my $count = 10000000;
- my $re = qr/abc/o;
- my %tests = (
- "NOFIND " => "cvxcvidgds.sdfpkisd[s"
- ,"FIND_AT_END " => "cvxcvidgds.sdfpabcd[s"
- ,"FIND_AT_START " => "abccvidgds.sdfpkisd[s"
- );
- foreach my $type (keys %tests) {
- my $str = $tests{$type};
- cmpthese($count, {
- "rege1.$type" => sub { my $idx = ($str =~ $re); },
- "rege2.$type" => sub { my $idx = ($str =~ /abc/o); }
- });
- }
- # Benchmark
- use Benchmark qw(:all);
- my $count = 10000000;
- my $re = qr/abc/o;
- my %tests = (
- "NOFIND " => "cvxcvidgds.sdfpkisd[s"
- ,"FIND_AT_END " => "cvxcvidgds.sdfpabcd[s"
- ,"FIND_AT_START " => "abccvidgds.sdfpkisd[s"
- );
- foreach my $type (keys %tests) {
- my $str = $tests{$type};
- cmpthese($count, {
- "rege1.$type" => sub { my $idx = ($str =~ $re); },
- "rege2.$type" => sub { my $idx = ($str =~ /abc/o); }
- });
- }
- use Benchmark 'cmpthese';
- my $re = qr/abc/o;
- my %tests = (
- 'fail ' => 'cvxcvidgds.sdfpkisd[s',
- 'end ' => 'cvxcvidgds.sdfpabcd[s',
- 'start' => 'abccvidgds.sdfpkisd[s',
- );
- for my $mag (map 10**$_, 1 .. 5) {
- say "n$mag:";
- for my $type (keys %tests) {
- my $str = $tests{$type};
- cmpthese -1, {
- '$re '.$type => sub {my $i; $i = ($str =~ $re ) for 0 .. $mag},
- '/abc/o '.$type => sub {my $i; $i = ($str =~ /abc/o) for 0 .. $mag},
- '/$re/ '.$type => sub {my $i; $i = ($str =~ /$re/ ) for 0 .. $mag},
- '/$re/o '.$type => sub {my $i; $i = ($str =~ /$re/o) for 0 .. $mag},
- }
- }
- }
- /.../o
- 1/661157 s - 1/4384042 s = 0.000,001,3 s
- 1/678702 s - 1/5117707 s = 0.000,001,3 s
- 1/657765 s - 1/4268032 s = 0.000,001,3 s
- >perl -MO=Concise,-exec -e"$x =~ /abc/"
- 1 <0> enter
- 2 <;> nextstate(main 1 -e:1) v:{
- 3 <#> gvsv[*x] s
- 4 </> match(/"abc"/) vKS/RTIME
- 5 <@> leave[1 ref] vKP/REFC
- -e syntax OK
- >perl -MO=Concise,-exec -e"$x =~ $re"
- 1 <0> enter
- 2 <;> nextstate(main 1 -e:1) v:{
- 3 <#> gvsv[*x] s
- 4 <1> regcreset sK/1
- 5 <#> gvsv[*re] s
- 6 <|> regcomp(other->7) sK/1
- 7 </> match() vKS/RTIME
- 8 <@> leave[1 ref] vKP/REFC
- -e syntax OK
Add Comment
Please, Sign In to add comment