closeio / quotequail

a library that identifies quoted text in email messages
MIT License
58 stars 23 forks source link

Speed up regex matching #11

Closed thomasst closed 8 years ago

thomasst commented 8 years ago

Python doesn't complain if you pass a regex object into re.match but there appears to be a speed difference:

In [1]: import re

In [2]: r = re.compile('x')

In [3]: %timeit re.match(r, 'x')
The slowest run took 7.74 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 2.34 µs per loop

In [4]: %timeit r.match('x')
The slowest run took 10.88 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 351 ns per loop