[Python-Dev] re performance

Serhiy Storchaka storchaka at gmail.com
Wed Feb 1 15:29:21 EST 2017

On 31.01.17 21:40, Wang, Peter Xihong wrote:
> Regarding to the performance difference between "re" and "regex" and packaging related options, we did a performance comparison using Python 3.6.0 to run some micro-benchmarks in the Python Benchmark Suite (https://github.com/python/performance):
> Results in ms, and the lower the better (running on Ubuntu 15.10)
> 				re		regex (via pip install regex, and a replacement of "import re" with "import regex as re")
> bm_regex_compile.py		229		298
> bm_regex_dna.py		171		267
> bm_regex_effbot.py		2.77		3.04
> bm_regex_v8.py		24.8		14.1
> This data shows "re" is better than "regex" in term of performance in 3 out of 4 above micro-benchmarks.

bm_regex_v8 is the one that is purposed to reflect real-world use of 
regular expressions.

See also different comparison at 
https://mail.python.org/pipermail/speed/2016-March/000311.html. In some 
tests regex surpasses re, in other tests re surpasses regex. re2 is much 
faster than other engines in all tests except the one in which it is 
much slower (and this engine is the least featured).

More information about the Python-Dev mailing list