[Mpls-pm] Interesting RegEx Problem
Ian Malpass
ian at indecorous.com
Mon Sep 19 19:25:23 PDT 2005
On Mon, 19 Sep 2005, Robert Fischer wrote:
> That's generally the plan right now. I'm more looking for good algorithms
> right now: I'll leave performance tweaks like "study" for if/when this
> hunk of code becomes a performance bottleneck worth being concerned about.
Then I would suggest doing two loops, with the inner one breaking when you
hit a match. Using qr// to pre-build the regexes (as we've done in the
various examples posted) will save you much of the overhead[0], as well as
making your code clearer.
It'll work, and it'll be clear, it'll be easy to debug, and it's an
isolated section of code that you can pull out and replace with a fancier
algorithm later. Later might be quite soon, but the two loops are five
minutes of code writing. Finish the whole app, benchmark it and profile
it, and then you'll know if getting fancy is (a) necessary, and (b)
effective. Without the benchmark of the simple solution, how will you know
how good your better algorithm is, and whether its worth losing clarity
and ease-of-maintenance for the performance improvement?
I'll stop now ;)
Ian
[0] Of course, we've been blithly assuming that the patterns are
loop-invariant, so precompiling them with qr// is valid, but I got that
impression from your problem statement :)
-
---------------------------------------------------------------------------
The soul would have no rainbows if the eyes held no tears.
Ian Malpass
<ian at indecorous.com>
More information about the Mpls-pm
mailing list