[issue21118] str.translate is absurdly slow in majority of use cases (takes up to 60x longer than similar functions)
STINNER Victor
report at bugs.python.org
Fri Apr 4 19:29:34 CEST 2014
STINNER Victor added the comment:
translate_script.py: microbenchmark for str.translate() with various length, charsets (ASCII, latin1, UCS2, UCS4) and percentage of replacement. Result:
---------------------------+----------+---------
Summary | original | writer
---------------------------+------+---------
replace none, length=10 | 5.65 us | 5.67 us
replace none, length=10**3 | 489 us | 486 us
replace none, length=10**6 | 487 ms | 484 ms
replace 10%, length=10 | 5.47 us | 5.48 us
replace 10%, length=10**3 | 455 us | 455 us
replace 10%, length=10**6 | 455 ms | 455 ms
replace 50%, length=10 | 4.71 us | 4.7 us
replace 50%, length=10**3 | 372 us | 374 us
replace 50%, length=10**6 | 371 ms | 373 ms
replace 90%, length=10 | 3.88 us | 3.93 us
replace 90%, length=10**3 | 293 us | 297 us
replace 90%, length=10**6 | 293 ms | 295 ms
replace all, length=10 | 3.58 us | 3.59 us
replace all, length=10**3 | 263 us | 262 us
replace all, length=10**6 | 262 ms | 261 ms
---------------------------+----------+---------
Total | 1.87 sec | 1.87 sec
---------------------------+----------+---------
It's exactly the same with translate_writer.patch.
----------
Added file: http://bugs.python.org/file34727/translate_script.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21118>
_______________________________________
More information about the Python-bugs-list
mailing list