[New-bugs-announce] [issue42706] random.uniform 2x slower than inline implementation
Scott Norton
report at bugs.python.org
Mon Dec 21 10:25:39 EST 2020
New submission from Scott Norton <pikalaxalt at gmail.com>:
The library function random.uniform takes about twice as long as a manual inline implementation (Python 3.9.1).
>>> import timeit
>>> timeit.timeit('3 + (8 - 3) * random.random()', 'import random')
0.1540887290000228
>>> timeit.timeit('a + (b - a) * random.random()', 'import random\na = 3\nb = 8')
0.17950458899986188
>>> timeit.timeit('random.uniform(3, 8)', 'import random') # does the call/return really add that much overhead?
0.31145418699999894
----------
components: C API
messages: 383532
nosy: Scott Norton
priority: normal
severity: normal
status: open
title: random.uniform 2x slower than inline implementation
type: performance
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42706>
_______________________________________
More information about the New-bugs-announce
mailing list