[Python-Dev] Revising RE docs

Gareth McCaughan gmccaughan at synaptics-uk.com
Mon Sep 5 14:57:34 CEST 2005

Guido wrote:

> > > They *are* cached and there is no cost to using the functions instead
> > > of the methods unless you have so many regexps in your program that
> > > the cache is cleared (the limit is 100).
> > 
> > Sure there is; the cost of looking them up in the cache.
> > So in this (highly artificial toy) application it's about 7.5/2.5 = 3 times
> > faster to use the methods instead of the functions.
> Yeah, but the cost is a constant -- it is not related to the cost of
> compiling the re.


>                   (You should've shown how much it cost if you
> included the compilation in each search.)

Why should I have? I don't dispute that the caching helps -- I bet it
helps a *lot*. I was just observing that it's not true that there's
"no cost to using the functions instead of the methods".

> I haven't looked into this, but I bet the overhead you're measuring is
> actually the extra Python function call, not the cache lookup itself.

Hmm, that's possible. But what matters in practice is how big
the cost of using re.search("...","...") rather than compiling
once and using the RE object's search method is, not where it
comes from.


More information about the Python-Dev mailing list