Re:PyPy 1.4: Ouroboros in practice
by orangecat on Friday November 26, 2010 @02:49PM
(#1943109)
Interesting and promising. PyPy 1.4:
Python 2.7:
Both running in 64-bit on a 2.53GHz Core 2 Duo. It looks like PyPy's JIT has some fixed overhead, but can heavily optimize operations once it gets going.
[ Parent
| on HN ]
There is something strange with the example.
$ pypy -mtimeit -s'import math; sin=math.sin' \
'[x*x+sin(x/1e6) for x in xrange(1000000)]'
10 loops, best of 3: 156 msec per loop
With no division it is slower (?): $ pypy -mtimeit -s'import math; sin=math.sin' \
'[x*x+sin(x) for x in xrange(1000000)]'
10 loops, best of 3: 188 msec per loop
CPython shows expected behavior: $ python2.7 -mtimeit -s'import math; sin=math.sin' \
'[x*x+sin(x) for x in xrange(1000000)]'
10 loops, best of 3: 231 msec per loop
$ python2.7 -mtimeit -s'import math; sin=math.sin' \
'[x*x+sin(x/1e6) for x in xrange(1000000)]'
10 loops, best of 3: 253 msec per loop
CPython is faster for tiny cases: $ pypy -mtimeit '[x*x for x in xrange(1000000)]'
10 loops, best of 3: 126 msec per loop
$ python2.7 -mtimeit '[x*x for x in xrange(1000000)]'
10 loops, best of 3: 67.3 msec per loop
$ pypy -mtimeit '[x*x*x for x in xrange(1000000)]'
10 loops, best of 3: 123 msec per loop
$ python2.7 -mtimeit '[x*x*x for x in xrange(1000000)]'
10 loops, best of 3: 118 msec per loopWith no division it is slower (?)
Very interesting. Looks like sin is faster for arguments less than pi/4 (~=0.7853981633974483):
Edit: "Intel's sin/cos implementation sucks golfballs through gardenhoses for arguments outside of [-pi/4,pi/4]": http://stackoverflow.com/questions/523531/fast-transcendent-...
$ pypy -mtimeit -s'import math; sin=math.sin; a=0.786' '[sin(a) for x in xrange(1000000)]'
10 loops, best of 3: 395 msec per loop
$ pypy -mtimeit -s'import math; sin=math.sin; a=0.785' '[sin(a) for x in xrange(1000000)]'
10 loops, best of 3: 375 msec per loop
$ python -mtimeit -s'import math; sin=math.sin; a=0.786' '[sin(a) for x in xrange(1000000)]'
10 loops, best of 3: 177 msec per loop
$ python -mtimeit -s'import math; sin=math.sin; a=0.785' '[sin(a) for x in xrange(1000000)]'
10 loops, best of 3: 155 msec per loop