That
DEBUGGING option is pretty powerful, thanks for the tip. That is proof
positive of what I have been suspecting, that Perl will
"compile" the regexps, but it doesn't perform any optimizations
in any intelligent sense. I was expecting a behaviour like
"lex", which takes an "expression" and returns a fairly
optimized state-machine which parses the defined tokens.
I am considering making an optimizer which will tweak a given
regexp into something more efficient, such that you could give
it something and it would polish it into something known to
Benchmark faster. Of course, discovering all the tricks would
be a bit of a chore, which is part of the challenge.
My idea is that this hypothetical function would take a
regexp as input and return the optimized, but functionally
equivalent, version of same:
Input Output
---------------------------------------
'x|xy' 'xy?'
'xx|xyx' 'xy?x'
'a|abc' 'a(bc)?'
'a|ab|abc' 'a(b(c)?)?'
'a1|a2|a3' 'a[123]'
The intention is to add optimization techniques as they
are discovered, plus an implementation strategy is devised.
Certainly, not every input regexp will be understood
to the degree that it can be optimized, and these will be
left undisturbed.
Already, I am finding that the "optimial" solution is
somewhat obscure in even simple cases:
/that|this|thinks|thirst|three/
-> /th(at|i(?:(?:nk)?s|rst)|ree/ ?
-> /th(?:at|is|inks|irst|ree)/ ?
-> /th(?:at|i(?:nk)?s|irst|ree)/ ?
Just food for thought.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.