I am currently trying to optimise a program. The major bottlenecks are actually fairly simple one-line calculations operating on numpy arrays, eg:
(p-1) * c**(p-1)/(v_dt+c)**p
(p & c here are floats and v_dt a ~500 long numpy array of float)
This calculation takes around 1/50 of a second on my machine
(Timed using timeit: 1000 loops, best of 3: 21.8 msec per loop)
The problem is that this small function (and I have several others like it) is called some 500 times for each iteration in a loop that runs variably around 100 times. So this one little line suddenly adds 20 minutes on to my runtime.
What are the best ways of speeding up mathematical calculations in python? How much can be done with python tricks? I have looked into c_types and possibly Cython but how can I use these? Do I need to write c code for these bottleneck functions or can I employ already compiled libraries (I have no experience with c).
Many thanks.
Edit: I forgot to mention, I am already looking at parallelisation options for the loops but still want to speed up these bottleneck functions directly as this is performance critical code