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 <rep...@bugs.python.org>
<http://bugs.python.org/issue28621>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to