Perl speed vs. Python speed

Gordon McMillan gmcm at hypernet.com
Wed Jan 12 12:11:37 EST 2000


Tom Culliton wrote:

> Fredrik Lundh <fredrik at pythonware.com> wrote:

> >if you can reorganize the
> >code to use a single regular expression on a larger string,
> >'re' beats the hell out of 'regex'.  ...and if you make things
> >complicated enough, 'regex' stops working... (but as usual,
> >some people prefer to get the wrong answer quickly ;-)
> 
> Big complicated regular expressions are a recipe for insanity.  Ask
> Tim, and he'll recommend using small simple regular expressions 9
> times out of 10.  At least thats how he's responded every time I've
> asked about problems with some excessively clever regular expression
> here.  Heck, I think you've even told me the same thing on at least
> one occasion. ;-)

Fredrik is emphasizing size of the string, not complexity of the 
expression. While re is also better at backtracking and the 
hairy stuff, the main correlation is with the size of the string 
being searched - regex is better at short inputs and falls off 
quickly thereafter.

Also, a long pattern is not necessarily a complex pattern. A 
humongous set of alternatives is no problem. The problem is 
when people expect to be able to do more than one thing at a 
time with a pattern.

Such as match an entire Python triple quoted string.

Which Tim does.

bad-Tim-<spank>-<spank>-ly y'rs


- Gordon




More information about the Python-list mailing list