Precompiled regular expressions slower?

Jon Ribbens jon+usenet at unequivocal.co.uk
Tue Feb 26 13:02:41 EST 2002


In article <3c7bb531$0$3930$b45e6eb0 at senator-bedfellow.mit.edu>,
  Peter Bienstman wrote:
> There are several reg ex in the loop. Since the Python version runs 2 to 3 
> times as slow as its Perl counterpart, I thought I'd try speeding up the 
> script by precompiling the reg ex:
> 
> re1 = compile(r"....") 
> ...
>   s = search(re1, line)

That's incorrect. The right syntax is:

  s = re1.search(line)

You should find this makes quite a big difference.



More information about the Python-list mailing list