Donovan Baarda added the comment:
Some points to note;
I first noticed this as an apparently 5x performance regression for randrange()
between pypy and pypy3. This seemed pretty significant, but admittedly the
difference is largely masked by other python overheads when comparing python2
Donovan Baarda added the comment:
I had a look at the C implementation of getrandbits() and spotted this;
https://github.com/python/cpython/blob/64fc105b2d2faaeadd1026d2417b83915af6622f/Modules/_randommodule.c#L487
In my case I was also being hit by randrange(2**32) calling getrandbits(33
Donovan Baarda added the comment:
FTR, more articles about the slowness of generating random integers in Python;
https://lemire.me/blog/2016/03/21/ranged-random-number-generation-is-slow-in-python/
https://www.reddit.com/r/Python/comments/jn0bb/randomrandint_vs_randomrandom_why_is_one_15x
Donovan Baarda added the comment:
I first noticed the problem when migrating a program doing lots of
randrange(2**32) calls from python2 (using pypy -O) to python3 (using pypy3 -O)
on Debian. The time results were;
pypy -O
real 3m58.621s
user 3m58.501s
sys 0m0.085s
pypy3 -O
real
Donovan Baarda added the comment:
Thanks @mark.dickinson for the heads up on that issue. Comments in the code
hinted that people had tried to tackle this but IMHO they missed the real fix.
I've submitted #24354 on github. It's missing an addition to the NEWS.d because
I wasn't sure
Change by Donovan Baarda :
--
keywords: +patch
pull_requests: +23174
stage: -> patch review
pull_request: https://github.com/python/cpython/pull/24354
___
Python tracker
<https://bugs.python.org/issu
New submission from Donovan Baarda :
I encountered a very significant slowdown migrating some code from python2.7 to
python3.9 that I tracked down to randrange() being slow. After digging I
noticed that _randbelow_with_getrandbits() calls getrandbits() 2x as many
times, and asks for one more
Donovan Baarda [EMAIL PROTECTED] added the comment:
On Tue, July 22, 2008 05:21, Martin v. Löwis wrote:
Martin v. Löwis [EMAIL PROTECTED] added the comment:
We would need the copyright holder of the patch to submit a contributor
form. Would that be possible?
he works for Google ([EMAIL
Donovan Baarda [EMAIL PROTECTED] added the comment:
One more time... this time after adding correct email addresses to my
existing account...
Martín Conte Mac Donell wrote:
Martín Conte Mac Donell [EMAIL PROTECTED] added the comment:
I made this patch works against trunk, also i'v fixed