[issue31671] IntFlag makes re.compile slower

STINNER Victor report at bugs.python.org
Thu Oct 5 06:10:57 EDT 2017


STINNER Victor <victor.stinner at gmail.com> added the comment:

Hum, I ran again my microbenchmark on re.compile() cache:

haypo at selma$ ./python -m perf timeit -s 'import re; re_compile=re.compile' 're_compile("a", flags=2)' --duplicate=1024 -o ref.json  --inherit=PYTHONPATH -v

Sadly, the commit c1c47c166b1012d34f2c6e111ee9ccb5c4d12de7 made the cache slower:

Mean +- std dev: [ref] 364 ns +- 26 ns -> [patch] 545 ns +- 19 ns: 1.50x slower (+50%)

Just to check, I reverted the change on Scanner, the benchmark is still "560 ns +- 27 ns".


"if isinstance(flags, RegexFlag): flags = flags.value" added 181 nanoseconds? A quick "isinstance(flags, RegexFlag)" timeit microbenchmark says that this operation has a cost of 46.2 ns (+- 1.6 ns). Benchmarks are strange, as usual :-)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31671>
_______________________________________


More information about the Python-bugs-list mailing list