On Thursday 2005-09-01 18:09, Guido van Rossum wrote:
> They *are* cached and there is no cost to using the functions instead
> of the methods unless you have so many regexps in your program that
> the cache is cleared (the limit is 100).
Sure there is; the cost of looking them up in the cache.
>>> import re,timeit
>>> timeit.re=re
>>> timeit.Timer("""re.search(r"(\d*).*(\d*)",
"abc123def456")""").timeit(1000000)
7.6042091846466064
>>> timeit.r = re.compile(r"(\d*).*(\d*)")
>>> timeit.Timer("""r.search("abc123def456")""").timeit(1000000)
2.6358869075775146
>>> timeit.Timer().timeit(1000000)
0.091850996017456055
So in this (highly artificial toy) application it's about 7.5/2.5 = 3 times
faster to use the methods instead of the functions.
--
g
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com