[New-bugs-announce] [issue33144] random._randbelow optimization

Wolfgang Maier report at bugs.python.org
Mon Mar 26 11:00:28 EDT 2018


New submission from Wolfgang Maier <wolfgang.maier at biologie.uni-freiburg.de>:

Given that the random module goes a long way to ensure optimal performance, I was wondering why the check for a match between the random and getrandbits methods is performed per call of Random._randbelow, when it could also be done at instantiation time (the attached patch uses __init_subclass__ for that purpose and, in my hands, gives 10-25% speedups for calls to methods relying on _randbelow).
Is it really necessary to guard against someone monkey patching the methods rather than using inheritance?

----------
components: Library (Lib)
files: randbelow.patch
keywords: patch
messages: 314455
nosy: rhettinger, wolma
priority: normal
severity: normal
status: open
title: random._randbelow optimization
type: performance
versions: Python 3.8
Added file: https://bugs.python.org/file47501/randbelow.patch

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33144>
_______________________________________


More information about the New-bugs-announce mailing list