[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 loop

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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) * 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.3114541869894

--
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com