good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^4: Help with Double Double Quotes regular expression (imprecise)by bart (Canon) |
on Apr 02, 2007 at 21:27 UTC ( [id://607926]=note: print w/replies, xml ) | Need Help?? |
Well, you might think it shouldn't make much of a difference, but perl happens to disagree with you. I disagree with you too, but it's probably perl that you'll rather listen to. :)
You see, there's only one way it could match, but there are plenty of ways it can fail (as in "almost succeed"). And a regex engine has a tendency to try them all, it's apparently not yet smart enough to know it can't succeed. Looking at the regex and the string "around", there's plenty of ways this could possibly match: Each phrase between parens indicates a group as matched by the subpattern [^"]+, and all groups are matched as a whole by * — as you can see, there are many ways it can be split up. If you use the "cut" operator, there's only one way this can match: So it makes sense to expect that using the cut operator might yield a significant speed boost. But, without further ado, here's the benchmark, as run with perl 5.8.8: Results (neither the figures, nor their ratios), are not always the same, so take with a grain of salt: That's a factor of 9, that /(?>[^"]+|"")*/ is faster than /(?:[^"]+|"")*/, for this string, and that is definitely not insignificant.
In Section
Seekers of Perl Wisdom
|
|