Regular expression matching performance

Moshe Zadka moshez at math.huji.ac.il
Fri Jun 9 13:12:44 EDT 2000


On Fri, 9 Jun 2000, John H. Zouck wrote:

> I'm a relative newbie to python, and have been rewriting a fairly simple
> perl program in python, mainly because I like python much better for
> structural and engineering reasons. The pythonprogram runsmuch more slowly
> then the perl program, and I set out to find out why. The  python profiler
> revealed the program was spending most if its time in regular expression
> matching, so I decided to find out if this was very much slower than perl. 

Writing Perl in Python is a hazardous affair. Perl's IO and REs are heavily
optimized, because that's what the language is used for the most. Python's
performance in those areas is worse. One way to lessen the difference is 
thinking a bit about the problem <wink>.

In your case, I'd recommend starting with a string.search(line, 'Loopback')
before going into the "re" code: it's much faster in python. If that isn't
fast enough, try to use Marc Andre Lemburg's mxTextTools 
(http://www.lemburg.com).

--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list