Reputation: 547
I have a program in python using numpy and scipy. adding cython in it will be a time taking process as there are many changes in data types
The cprofile of it looks like this: https://i.sstatic.net/O2J9O.jpg
Most of the time (73% ) is used up by <scipy.integrate_odepack.odeint>
My question basically is, does using cython speed up this function(maybe by faster calling) and the rest.
This function is called ~10^6 times in this example.
And if so, How much speed up can I expect?
I consider pursuing this if speed up is atleast 4x to 5x
note:
If the information provided is insufficient, please comment below and I'd be glad to provide
Thank you
Upvotes: 3
Views: 1393
Reputation: 7755
Well half of the time of <scipy.integrate_odepack.odeint>
is being spent inside dx_dv
and dx_du
these look like they're python functions. These are functions you could target especially if they are complex.
One thing to bear in mind is that if the slow down is just because of the calling overhead * number of calls
then I wouldn't expect things to improve much. That overhead won't disappear, in fact it might be made more complex. Instead of SciPy C -> Python, you'll be doing SciPy C -> Python -> your C.
Upvotes: 3
Reputation: 10961
Chances are you're not going to see much (if any) improvement. SciPy (and even more specific the code you're most interested in, odeint
) is already a CPython module(written in Fortran), not just python.
If this were a python-only function call, then writing it in Cython (which can be easier than writing a full blown CPython module, though personally I'd write a c or c++ dll and call it using ctypes...) would increase your performance. But probably not in this situation.
Upvotes: 3