[New-bugs-announce] [issue28621] Refactor duplicate code calculating digit's bit length
Adrian Wielgosik
report at bugs.python.org
Sat Nov 5 15:37:28 EDT 2016
New submission from Adrian Wielgosik:
The attached patch uses an existing function bits_in_digit() in two other functions:
- in long_bit_length() - it already had identical logic
- in _PyLong_NumBits() - it used a naive, slower way of calculating bit length, so as an added bonus the patch speeds it up a bit. It's visible in float-long comparison microbenchmark:
$ ./old -m timeit "1 == 1.0"
5000000 loops, best of 5: 55 nsec per loop
$ ./new -m timeit "1 == 1.0"
5000000 loops, best of 5: 52.3 nsec per loop
$ ./old -m timeit "12345678 == 12345678.0"
5000000 loops, best of 5: 70.4 nsec per loop
$ ./new -m timeit "12345678 == 12345678.0"
5000000 loops, best of 5: 53.5 nsec per loop
----------
components: Interpreter Core
messages: 280123
nosy: Adrian Wielgosik
priority: normal
severity: normal
status: open
title: Refactor duplicate code calculating digit's bit length
type: performance
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28621>
_______________________________________
More information about the New-bugs-announce
mailing list