Regex speed

Erik Heneryd erik at heneryd.com
Sat Oct 30 11:56:12 EDT 2004


Reinhold Birkenfeld wrote:
> OK, thank you. I now got rid of all the regexes, and - surprise,
> surprise - the speeds are almost equal. The bitter thing about it is
> that there are now twelve LOC more in Python that don't make
> understanding the code easier.

If your problem is that the re.compile() setup takes too long (compared 
to the time taken to do the actual matching/replacing), my guess is that 
you don't operate on that much data.  And if that's the case, does it 
really matter if it's a fraction of a second slower?

Note that str.find() currently uses the naive approach resulting in bad 
time complexity, so it's not suitable for larger data sets.  See 
http://online.effbot.org/2004_08_01_archive.htm#find


Erik



More information about the Python-list mailing list