This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Faster getrandbits() for small integers
Type: performance Stage: resolved
Components: Extension Modules Versions: Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: jcea, mark.dickinson, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2012-12-13 20:54 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
random_getrandbits_fastpath.patch serhiy.storchaka, 2012-12-13 20:54 review
Messages (3)
msg177436 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-13 20:54
The proposed patch adds a fast patch for generating small integers (the most common use case).

$ ./python -m timeit -s "import random; r=random.getrandbits; n=30"  "r(n);r(n);r(n);r(n);r(n);r(n);r(n);r(n);r(n);r(n)"

Non patched: 4.27 usec per loop
Patched: 2.97 usec per loop
msg178990 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-01-03 21:33
Looks good to me.
msg179012 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-01-04 10:20
New changeset b0926ddcab5e by Serhiy Storchaka in branch 'default':
Issue #16674: random.getrandbits() is now 20-40% faster for small integers.
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 60878
2013-01-04 10:21:59serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2013-01-04 10:20:54python-devsetnosy: + python-dev
messages: + msg179012
2013-01-03 21:33:42mark.dickinsonsetmessages: + msg178990
2012-12-29 21:59:50serhiy.storchakasetassignee: serhiy.storchaka
2012-12-13 21:23:27jceasetnosy: + jcea
2012-12-13 20:54:36serhiy.storchakacreate