PerlBhikkhuni has asked for the wisdom of the Perl Monks concerning the following question:
Running the following script on these two versions of perl (5.8.8 and 5.16.2) shows that 5.16.2 is slower than 5.8.8 with regex-operations. Why is that so ? And, is there a way i can speed things up ?
use Time::HiRes 'time'; for my $regex ( q{^a$|^b$}, q{^(a|b)$}, q{(a|b)}, q{^a$|^b$|^c$|^d$|^e$|^f$}, q{^(a|b|c|d|e|f)$}, q{a|b|c|d|e|f}, ) { my $start = time(); for my $i (1 .. 100_000) { 'SOMEBIGSTRINGHERE' =~ m{$regex}; } my $runtime = time() - $start; printf("%50s: %f\n", $regex, $runtime); } with perl 5.8.8 - ^a$|^b$: 0.101017 ^(a|b)$: 0.017527 (a|b): 0.107669 ^a$|^b$|^c$|^d$|^e$|^f$: 0.163687 ^(a|b|c|d|e|f)$: 0.022244 a|b|c|d|e|f: 0.171675 with perl 5.16.2 - ^a$|^b$: 0.254984 ^(a|b)$: 0.031507 (a|b): 0.045713 ^a$|^b$|^c$|^d$|^e$|^f$: 0.443303 ^(a|b|c|d|e|f)$: 0.031506 a|b|c|d|e|f: 0.043478
Also, how do we know that a regex is precompiled ? From http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators,
$rex = qr/my.STRING/is; print $rex; # prints (?si-xm:my.STRING) s/$rex/foo/;
this prints (?si-xm:my.STRING) in 5.8.8 and ((?^si:my.STRING)) in 5.16.2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is regcomp slower in 5.16.2 than in 5.8.8. How to speed things up ?
by dave_the_m (Monsignor) on May 29, 2013 at 12:51 UTC | |
by PerlBhikkhuni (Initiate) on May 29, 2013 at 17:03 UTC | |
|
Re: Is regcomp slower in 5.16.2 than in 5.8.8. How to speed things up ?
by choroba (Cardinal) on May 29, 2013 at 10:43 UTC | |
|
Re: Is regcomp slower in 5.16.2 than in 5.8.8. How to speed things up ?
by vsespb (Chaplain) on May 29, 2013 at 10:27 UTC | |
by PerlBhikkhuni (Initiate) on May 29, 2013 at 17:07 UTC |