NEWBIE: ishexdigit revisited
Kirk Strauser
kirk at strauser.com
Tue Dec 30 16:15:11 EST 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2003-12-30T19:52:01Z, Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> It normally only gets compiled once anyway, then cached. If you
> have a really large number of different regexps I guess the cache
> can overflow and recompilation happens.
I'm not seeing that here with 2.3.3:
>>> 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.39079892635
>>> start = time.time(); retest(); stop = time.time(); print stop - start
5.28148591518
>>> start = time.time(); retest2(); stop = time.time(); print stop - start
1.0404009819
>>> start = time.time(); retest2(); stop = time.time(); print stop - start
1.04278099537
Pre-compiling the pattern is a huge win on my system.
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/8erD5sRg+Y0CpvERAtr8AJ43Ae2HO94T8uji3EsMRiLtRcDEEACeOhz6
Ouaa03uSgyVYkbtm2ETgZ9Q=
=rbH6
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list