|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
alternation in regexes: to use or to avoid?by dk (Chaplain) |
| on Dec 10, 2012 at 14:42 UTC ( #1008105=perlquestion: print w/ replies, xml ) | Need Help?? |
|
dk has asked for the
wisdom of the Perl Monks concerning the following question:
Dear monks,
I've hit a performance issue with using | in regexes. It seems that in some (not-so-degenerated, actually) cases it loses significantly to looping over simple regexes i.e. $str =~ /$_// for @rx is much faster than $str =~ /$rx[0]|$rx[1]|$rx[2]/, which is rather counter-intuitive. Basically, for general cases, it would mean that alterations with grouping should be avoided at all, which is a strong statement and I wouldn't like it that way. Is this a recognized problem? Is it a problem at all? Does it look like it needs to be reported as a bug? I can't decide myself. Here's the test code:
Here's the output:
Update: got same results on perls 5.10.1, 5.16.0, and 5.17.6
Back to
Seekers of Perl Wisdom
|
|