[pypy-issue] Issue #3142: Performance with simple numpy arrays (pypy/pypy)
Pierre Augier
issues-reply at bitbucket.org
Sun Jan 5 15:56:46 EST 2020
New issue 3142: Performance with simple numpy arrays
https://bitbucket.org/pypy/pypy/issues/3142/performance-with-simple-numpy-arrays
Pierre Augier:
I’m having a look at how much Python is bad with callbacks of tiny functions \([https://github.com/paugier/bench\_integrate\_callback](https://github.com/paugier/bench_integrate_callback)\). I was motivated by a benchmark from Julia people showing than Julia is much faster than Scipy for ODEs integration with tiny callback functions \([https://github.com/JuliaDiffEq/SciPyDiffEq.jl](https://github.com/JuliaDiffEq/SciPyDiffEq.jl)\).
I thought that PyPy could be good to accelerate \`scipy.integrate.solve\_ivp\` since the code of solve\_ivp \([https://github.com/scipy/scipy/tree/master/scipy/integrate/\_ivp](https://github.com/scipy/scipy/tree/master/scipy/integrate/_ivp)\) is mostly “simple” Python using “simple” Numpy. However, it’s much slower with PyPy.
I isolated a very simple case with a callback to check what happens.
With a pure Python version \([https://github.com/paugier/bench\_integrate\_callback/blob/master/purepython\_callback.py](https://github.com/paugier/bench_integrate_callback/blob/master/purepython_callback.py)\), PyPy is 30 times faster than CPython! However, with a versions for which the time values are stored in a Numpy array \([https://github.com/paugier/bench\_integrate\_callback/blob/master/numpy\_callback.py](https://github.com/paugier/bench_integrate_callback/blob/master/numpy_callback.py)\), PyPy is 54 times slower than for the version for which the time values are stored in a list \(therefore nearly 2 times slower than CPython\).
The only difference between the 2 scripts is \`times = dt \* np.arange\(1e5\)\` instead of \`times = \[dt \* it for it in range\(int\(1e5\)\)\]\`. Of course, most of the elapsed time is not spent in this line but in the loop.
It’s sad that PyPy can’t accelerate Python code using simple Numpy. I realized that it is not something new, but still I’d like to ask if there is any chance that PyPy could be improved in that respect.
More information about the pypy-issue
mailing list