Performance with simple numpy arrays
Created originally on Bitbucket by paugier (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). 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).
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) 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), 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), 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.