[issue26574] replace_interleave can be optimized for single character byte strings

STINNER Victor report at bugs.python.org
Mon Mar 21 05:39:25 EDT 2016


STINNER Victor added the comment:

I wrote a microbenchmark with my benchmark.py tool.

The patch always make bytes.replace(b'', char) and bytearray.replace(b'', char) faster even for strings of 10 bytes, the speedup on string of 1000 bytes or more is very interesting, even I never used this Python instruction :-)

-------------+-------------+---------------
type bytes   |        orig |          patch
-------------+-------------+---------------
length=10    |  250 ns (*) |  211 ns (-15%)
length=10**3 | 4.67 us (*) | 1.07 us (-77%)
length=10**5 |  441 us (*) | 78.2 us (-82%)
-------------+-------------+---------------
Total        |  446 us (*) | 79.5 us (-82%)
-------------+-------------+---------------

---------------+-------------+---------------
type bytearray |        orig |          patch
---------------+-------------+---------------
length=10      |  266 ns (*) |  224 ns (-16%)
length=10**3   | 4.67 us (*) | 1.08 us (-77%)
length=10**5   |  441 us (*) | 78.3 us (-82%)
---------------+-------------+---------------
Total          |  446 us (*) | 79.6 us (-82%)
---------------+-------------+---------------

---------------+------------+---------------
Summary        |       orig |          patch
---------------+------------+---------------
type bytes     | 446 us (*) | 79.5 us (-82%)
type bytearray | 446 us (*) | 79.6 us (-82%)
---------------+------------+---------------
Total          | 892 us (*) |  159 us (-82%)
---------------+------------+---------------

----------
Added file: http://bugs.python.org/file42229/bench.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26574>
_______________________________________


More information about the Python-bugs-list mailing list