NEWBIE: ishexdigit revisited
Paul Rubin
http
Tue Dec 30 16:45:13 EST 2003
Kirk Strauser <kirk at strauser.com> writes:
> >>> def retest():
> ... for i in xrange(1000000):
> ... re.match(r'unlikely.*pat(..(.))?tern$', 'test')
> ...
> >>> def retest2():
> ... pat = re.compile(r'unlikely.*pat(..(.))?tern$')
> ... for i in xrange(1000000):
> ... pat.match('test')
> ...
> >>> start = time.time(); retest(); stop = time.time(); print stop - start
> 5.28148591518
> >>> start = time.time(); retest2(); stop = time.time(); print stop - start
> 1.04278099537
>
> Pre-compiling the pattern is a huge win on my system.
You're using an extreme example and seeing the cost of the cache
lookup in the first example. You're certainly not seeing the pattern
get recompiled a million times in 5 seconds. Doing would be many
times slower.
More information about the Python-list
mailing list