classification
Title: Refactor duplicate code calculating digit's bit length
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Adrian Wielgosik, mark.dickinson, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-11-05 19:37 by Adrian Wielgosik, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
bit_length.patch Adrian Wielgosik, 2016-11-05 19:38 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (5)
msg280123 - (view) Author: Adrian Wielgosik (Adrian Wielgosik) * Date: 2016-11-05 19:37
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
msg280131 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-11-06 07:45
LGTM.
msg280240 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2016-11-07 20:58
LGTM, too.
msg280331 - (view) Author: Roundup Robot (python-dev) Date: 2016-11-08 18:34
New changeset 1940b72b0a02 by Serhiy Storchaka in branch 'default':
Issue #28621: Sped up converting int to float by reusing faster bits counting
https://hg.python.org/cpython/rev/1940b72b0a02
msg280333 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-11-08 18:36
Thank you Adrian for your contribution.
History
Date User Action Args
2017-03-31 16:36:09dstufftsetpull_requests: + pull_request845
2016-11-08 18:36:05serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg280333

stage: commit review -> resolved
2016-11-08 18:34:46python-devsetnosy: + python-dev
messages: + msg280331
2016-11-07 20:58:51mark.dickinsonsetmessages: + msg280240
2016-11-06 07:45:12serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg280131
stage: patch review -> commit review
2016-11-05 21:42:48SilentGhostsetnosy: + mark.dickinson

stage: patch review
2016-11-05 19:38:13Adrian Wielgosiksetfiles: + bit_length.patch
keywords: + patch
2016-11-05 19:37:28Adrian Wielgosikcreate