[Tutor] improving speed using and recalling C functions

Danny Yoo dyoo at hashcollision.org
Thu Apr 10 21:09:55 CEST 2014

Hi Gabriele,

Have you profiled your program?  Please look at:


If you can, avoid guessing what is causing performance to drop.
Rather, use the tools in the profiling libraries to perform

It may be that your program is taking a long time because of something
obvious, but perhaps there is some other factor that's contributing.
Please do this.  More details would be helpful.  Are you using any
libraries such as Numpy?  Just writing something in C doesn't
magically make it go faster.  CPython is written in C, for example,
and yet people do not say that Python itself is very fast.  :P

It may be the case that writing the computations in C will allow you
to specify enough type information so that the computer can
effectively run your computations quickly.  But if you're using
libraries like Numpy to do vector parallel operations, I would not be
surprised if that would outperform native non-parallel C code.



which demonstrates that effective use of NumPy may speed up
computations by a significant order of magnitude, if you use the
library to take advantage of its vectorizing compuations.

More domain-specific details may help folks on the tutor list to give
good advice here.

More information about the Tutor mailing list