[issue24059] Minor speed and readability improvement to the random module

Mark Dickinson report at bugs.python.org
Sun Apr 26 19:29:49 CEST 2015


Mark Dickinson added the comment:

Timing results on my machine:

(Canopy 64bit) taniyama:~ mdickinson$ python3 -m timeit -s "from math import sqrt; x = 3.14" "sqrt(x)"
10000000 loops, best of 3: 0.0426 usec per loop
(Canopy 64bit) taniyama:~ mdickinson$ python3 -m timeit -s "from math import sqrt; x = 3.14" "x**0.5"
10000000 loops, best of 3: 0.0673 usec per loop

And the disassembly showing the peephole optimizer at work:

>>> def f(): return 3.14**0.5
... 
>>> import dis
>>> dis.dis(f)
  1           0 LOAD_CONST               3 (1.772004514666935)
              3 RETURN_VALUE

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24059>
_______________________________________


More information about the Python-bugs-list mailing list