Subject: | False performance claims in POD |
"only impacts the performance of matches that you specify."
I ran several Benchmarks for comparison, and it seems to still
impact performance (this is 5.8.4) on non-match-capturing expressions
due to the fact that the overloaded qr still includes a code block
(?-xism:(?{$Regexp::MatchContext::target_ref=undef})[^aeiou]{3})
Below is my test code:
use Benchmark;
# my $RE = qr/(?p)[^aeiou]{3}/;
use English; my $RE = qr/[^aeiou]{3}/;
#use Regexp::MatchContext -vars; my $RE = qr/(?p)[^aeiou]{3}/;
#use Regexp::MatchContext -vars; my $RE = qr/[^aeiou]{3}/;
timethis(100_000 => sub{
foreach( qw/hippopotamus
Schadenfreude
xyzzy
supercalifragilisticexpialidocious/ ){
1 if /$RE/;
}
}
);
__END__
Perl
timethis 100000: 2 wallclock secs ( 1.85 usr + 0.00 sys = 1.85 CPU) @
54083.29/s (n=100000)
timethis 200000: 4 wallclock secs ( 3.71 usr + -0.00 sys = 3.70 CPU) @
53981.11/s (n=200000)
E
timethis 100000: 3 wallclock secs ( 1.90 usr + 0.00 sys = 1.90 CPU) @
52742.62/s (n=100000)
timethis 200000: 5 wallclock secs ( 3.80 usr + 0.00 sys = 3.80 CPU) @
52687.04/s (n=200000)
RMC w/p
timethis 100000: 7 wallclock secs ( 6.92 usr + 0.00 sys = 6.92 CPU) @
14446.69/s (n=100000)
timethis 200000: 14 wallclock secs (13.60 usr + 0.00 sys = 13.60 CPU) @
14704.80/s (n=200000)
RMC no-p
timethis 100000: 3 wallclock secs ( 4.06 usr + 0.00 sys = 4.06 CPU) @
24636.61/s (n=100000)
timethis 200000: 8 wallclock secs ( 8.06 usr + 0.00 sys = 8.06 CPU) @
24823.14/s (n=200000)
This patch
--- site_perl/5.8.0/Regexp/MatchContext.pm~ Thu Aug 4 01:58:14 2005
+++ site_perl/5.8.0/Regexp/MatchContext.pm Wed Dec 24 15:00:16 2008
@@ -33,8 +33,7 @@
}
{ push @vars, "undef\$$1;";
"($2)(?{eval'\$$1=\$^N'})" }gex
and $raw =~ s/$/|(??{@vars'(?!)'})/;
- $raw =~
s/\(\?p\)/(?{\$Regexp::MatchContext::target_ref=\\\$_})/g
- or $raw =~
s/\A/(?{\$Regexp::MatchContext::target_ref=undef})/;
+ $raw =~
s/\(\?p\)/(?{\$Regexp::MatchContext::target_ref=\\\$_})/g;
return $raw;
};
Gives performance as documented:
timethis 100000: 2 wallclock secs ( 1.84 usr + 0.00 sys = 1.84 CPU) @
54377.38/s (n=100000)
timethis 200000: 4 wallclock secs ( 3.69 usr + 0.00 sys = 3.69 CPU) @
54156.51/s (n=200000)