[pypy-dev] works in python2.4, fails in pypy

Ondrej Certik ondrej at certik.cz
Mon Aug 25 13:28:49 CEST 2008


On Mon, Aug 25, 2008 at 1:04 PM, Maciej Fijalkowski <fijall at gmail.com> wrote:
>>
>> So pypy is roughly 4.7x slower on this particular thing.
>>
>> Do you have any plans to release pypy? I think it's getting very useful.
>>
>> Ondrej
>>
>
> Yes, we have some plans to have a release at some point soon. There
> are no details though. Note that if you do this:
>
> from sympy import *
> var('x')
> from timeit import default_timer as clock
> t = clock(); a= sin(x).series(x, 0, 100); t = clock()-t; print t
> var('y')
> t = clock(); a= sin(y).series(y, 0, 100); t = clock()-t; print
>
> gap between pypy and cpython is getting smaller (some startup time is
> particularly large). I can do a bit profiling if you like.

Use SYMPY_USE_CACHE=no when doing repeated profiling, otherwise you
are just measuring how fast our cache is.

ondra at pc232:~/repos/sympy$ SYMPY_USE_CACHE=no
~/repos/pypy-dist/pypy/translator/goal/pypy-c
Python 2.4.1 (pypy 1.0.0 build 57617) on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``- PyPy status blog:
http://morepypy.blogspot.com/''
>>>> from sympy import *
>>>> var('x')
x
>>>> from timeit import default_timer as clock
>>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
3.56681609154
>>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
3.2662088871
>>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
3.22522711754
>>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
3.24221301079
>>>>


ondra at pc232:~/repos/sympy$ SYMPY_USE_CACHE=no python
Python 2.5.2 (r252:60911, Aug  8 2008, 09:22:44)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> var('x')
x
>>> from timeit import default_timer as clock
>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
0.83996295929
>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
0.739042043686
>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
0.73944401741
>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
0.739789009094


We are in the process of speeding up sympy, you can also play with our
experimental core that doesn't use caching:

$ git clone git://github.com/certik/sympyx.git
$ cd sympyx
$ ~/repos/pypy-dist/pypy/translator/goal/pypy-c
Python 2.4.1 (pypy 1.0.0 build 57617) on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``"peephope" optimizations are what
an optimistic Compiler uses''
>>>> from sympy import var
I: import sympy_pyx ... fail  (No module named sympy_pyx)
W: can't import sympy_pyx -- will be pure python
>>>> var("x y z")
(x, y, z)
>>>> e = (x+y+z+1)**40
>>>> from timeit import default_timer as clock
>>>> t = clock(); a= e.expand(); t = clock()-t; print t
2.6539349556
>>>> t = clock(); a= e.expand(); t = clock()-t; print t
2.73331212997
>>>> t = clock(); a= e.expand(); t = clock()-t; print t
2.76934981346
>>>>

$ python
Python 2.5.2 (r252:60911, Aug  8 2008, 09:22:44)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import var
I: import sympy_pyx ... fail  (No module named sympy_pyx)
W: can't import sympy_pyx -- will be pure python
>>> var("x y z")
(x, y, z)
>>> e = (x+y+z+1)**40
>>> from timeit import default_timer as clock
>>> t = clock(); a= e.expand(); t = clock()-t; print t
0.867521047592
>>> t = clock(); a= e.expand(); t = clock()-t; print t
1.13780593872
>>> t = clock(); a= e.expand(); t = clock()-t; print t
1.13062214851
>>> t = clock(); a= e.expand(); t = clock()-t; print t
1.14683890343
>>> t = clock(); a= e.expand(); t = clock()-t; print t
1.17529797554


So for that pypy is only 2x to 3x slower.

BTW, when you compile our core using Cython, it get's way faster:

$ make
cython --convert-range sympy_pyx.pyx
gcc -I/usr/include/python2.5 -I/usr/include/python2.5	 -g -O0 -fPIC
-c -o sympy_pyx.o sympy_pyx.c
gcc  -shared sympy_pyx.o -o sympy_pyx.so
$ python
Python 2.5.2 (r252:60911, Aug  8 2008, 09:22:44)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import var
I: import sympy_pyx ... ok
>>> var("x y z")
(Symbol(x), Symbol(y), Symbol(z))
>>> e = (x+y+z+1)**40
>>> from timeit import default_timer as clock
>>> t = clock(); a= e.expand(); t = clock()-t; print t
0.214432001114
>>> t = clock(); a= e.expand(); t = clock()-t; print t
0.271343946457
>>> t = clock(); a= e.expand(); t = clock()-t; print t
0.239308834076



Do you have any plans for supporting writing C extensions to pypy?
Because as you can see above, the speed is imho only possible when
writing it in C. Well, if RPython could produce as optimized code as
Cython, then it could be an option. Any ideas on that?


Ondrej



More information about the Pypy-dev mailing list