[issue42706] random.uniform 2x slower than inline implementation

2020-12-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: > does the call/return really add that much overhead? Yes, it does. $ python3.9 -m timeit -s 'x=3.5' 'x**2' 500 loops, best of 5: 63.5 nsec per loop $ python3.9 -m timeit -s 'x=3.5' -s 'f=lambda x: x**2' 'f(x)' 200 loops, best of 5: 136 nsec per

[issue42706] random.uniform 2x slower than inline implementation

2020-12-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Yes, calling functions in Python has some overhead. It is not specific to random.uniform(). -- nosy: +rhettinger, serhiy.storchaka ___ Python tracker

[issue42706] random.uniform 2x slower than inline implementation

2020-12-21 Thread Scott Norton
New submission from Scott Norton : 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.154088729228 >>> timeit.timeit('a + (b - a) *