Regular Expressions - Python vs Perl

Ville Vainio ville at spammers.com
Fri Apr 22 10:14:17 EDT 2005


>>>>> "Ilpo" == Ilpo Nyyssönen <iny> writes:

    Ilpo> Of course it caches those when running. The point is that it
    Ilpo> needs to recompile every time you have restarted the
    Ilpo> program. With short lived command line programs this really
    Ilpo> can be a problem.

I didn't imagine it could be longer than 1 second overhead - and if
you have so many regexps, it must do something so nontrivial that 1
second doesn't matter. Perhaps I have a different mindset about this
:-).

    Ilpo> And yes, I have read the source of sre.py and I have made an
    Ilpo> ugly module that digs the compiled data and pickles it to a
    Ilpo> file and then in next startup it reads that file and puts
    Ilpo> the stuff back to the cache.

What's so ugly about it? The fact that you need to rewrite the cache
when you change some of the regexps? I can't imagine you change more
than, say, 10 of the regexps a day (compiling of which is an
insignificant performance hit) and when you "ship" the script, you
will freeze the regexps anyway.

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list