[issue29421] Make int.to_bytes() and int.from_bytes() slightly faster

Serhiy Storchaka report at bugs.python.org
Thu Feb 2 09:31:54 EST 2017


New submission from Serhiy Storchaka:

Proposed patch makes int.to_bytes() and int.from_bytes() slightly faster.

$ ./python -m perf timeit '1 .to_bytes(4, "little")' --compare-to "`pwd`/python0"
Median +- std dev: [python0] 1.28 us +- 0.07 us -> [python] 1.17 us +- 0.07 us: 1.09x faster (-8%)

$ ./python -m perf timeit '1 .to_bytes(4, "big")' --compare-to "`pwd`/python0"
Median +- std dev: [python0] 1.30 us +- 0.07 us -> [python] 1.19 us +- 0.05 us: 1.10x faster (-9%)

$ ./python -m perf timeit 'int.from_bytes(b"\1\0\0\0", "little")' --compare-to "`pwd`/python0"
Median +- std dev: [python0] 1.70 us +- 0.13 us -> [python] 1.41 us +- 0.06 us: 1.20x faster (-17%)

$ ./python -m perf timeit 'int.from_bytes(b"\0\0\0\1", "big")' --compare-to "`pwd`/python0"
Median +- std dev: [python0] 1.71 us +- 0.15 us -> [python] 1.40 us +- 0.05 us: 1.22x faster (-18%)

----------
components: Interpreter Core
files: int-to_bytes-from_bytes.patch
keywords: patch
messages: 286796
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Make int.to_bytes() and int.from_bytes() slightly faster
type: performance
versions: Python 3.7
Added file: http://bugs.python.org/file46491/int-to_bytes-from_bytes.patch

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


More information about the Python-bugs-list mailing list