[Tutor] regexp are fast - was: newbie search and replace

Michael Janssen Janssen@rz.uni-frankfurt.de
Tue Jan 28 13:28:01 2003


On Tue, 28 Jan 2003 alan.gauld@bt.com wrote:

> > My first concern was that many global subtitions over a long
> > string would last a long time.
>
> True but probably less time with a well designed RE than with
> multiple string searches with lots of safety checks.

I've played a bit with "findall", rewritten the core of a script of mine,
which I've written throughout the summer within twenty minutes, made it
far more stable and voila: even incredibly faster than my first attempt
(at least factor 2 with first try):

What I've learned this afternoon and last night is:
re's findall over a large string is much faster than many single
string or re-operations while iterating line by line over a file.

Yes, well designed RE's are fast.

Michael

[me - yesterday]
> > stucks most the runtime computing RE's where perl
> > aequivalents have done the job already - it's terrible subjective,
> > but I believe python's RE slow).
okey, I've changed my opinion about this :-) "You learn more, and the
language scales up"

>
> The C versions are pretty good, they are slower than Perl mainly
> because they are not builtin to the language but apart from module
> overhead they are not that much slower. I think Python's bad reputation
> for REs is largely based on the original regex module written in
> Python. Dirt sticks, even after its been cleaned off sometimes!
>
> Alan g.
> Author of the Learn to Program website
> http://www.freenetpages.co.uk/hp/alan.gauld/
>