[issue17301] An in-place version of many bytearray methods is needed
Serhiy Storchaka
report at bugs.python.org
Wed Jan 4 05:40:40 EST 2017
Serhiy Storchaka added the comment:
> The important reasons for this are memory use and cache thrashing, not just
> CPU time.
Memory use is not an issue unless you translate hundreds of megabytes at a time. Cache trashing at the end is performance issue.
The original patch is no longer applied cleanly. Here is a patch synchronized with current sources and with fixed one error. I didn't look at it closely and don't know whether it has other bugs.
Here are results of microbenchmarking.
$ ./python -m perf timeit -s "table = bytes(range(256)).swapcase(); data = bytearray(range(256))*1000" -- "data = data.translate(table)"
Median +- std dev: 1.48 ms +- 0.02 ms
$ ./python -m perf timeit -s "table = bytes(range(256)).swapcase(); data = bytearray(range(256))*1000" -- "data[:] = data.translate(table)"
Median +- std dev: 1.60 ms +- 0.09 ms
$ ./python -m perf timeit -s "table = bytes(range(256)).swapcase(); data = bytearray(range(256))*1000" -- "data.mtranslate(table)"
Median +- std dev: 1.79 ms +- 0.07 ms
In-place translate don't have benefits. It is slower that translate with creating a new copy, and even is slower that translate with copying a new copy back.
----------
Added file: http://bugs.python.org/file46137/issue17301-2.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17301>
_______________________________________
More information about the Python-bugs-list
mailing list