[Python-Dev] Speeding up regular expression compilation

Bram Moolenaar Bram at moolenaar.net
Thu Oct 30 14:08:19 EST 2003


In the python-dev archives I find remarks about the old pre module being
much faster at compiling regular expressions than the new sre module.
My own experiences are that pre is about twenty times as fast.

Since my application uses a lot of simple patterns which are matched on
short strings (file names actually), the pattern compilation time is
taking half the CPU cycles of my program.  The faster execution of sre
apparently doesn't compensate for the slower compile time.

Is the plan to implement the sre module in C getting closer to being
done?

Is there a trick to make compiling patterns go faster?

I'm already falling back to the pre module with Python 2.2 and older.
With Python 2.3 this generates a warning message, thus I don't do it
there.

I considered copying the 2.2 version of pre.py into my application, but
this will stop working as soon as the support for pre is dropped (the
compiled C code won't be there).  Thus it would be only a temporary fix.

I don't care about the Unicode support.

-- 
LAUNCELOT: Isn't there a St. Aaaaarrrrrrggghhh's in Cornwall?
ARTHUR:    No, that's Saint Ives.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram at Moolenaar.net -- http://www.Moolenaar.net   \\\
///          Creator of Vim - Vi IMproved -- http://www.Vim.org          \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///



More information about the Python-Dev mailing list