[Python-Dev] Revising RE docs (original) (raw)
Gareth McCaughan gmccaughan at synaptics-uk.com
Fri Sep 2 12:40:35 CEST 2005
- Previous message: [Python-Dev] Revising RE docs
- Next message: [Python-Dev] Revising RE docs
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] Revising RE docs
- Next message: [Python-Dev] Revising RE docs
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]