[Tutor] improving speed using and recalling C functions
Alan Gauld
alan.gauld at btinternet.com
Thu Apr 10 19:26:12 CEST 2014
On 10/04/14 16:58, Gabriele Brambilla wrote:
> For each element it performs 200 times a particular mathematical
> operation (a numerical interpolation of a function).
> Now these process takes near 8 hours.
The first thing to do in such cases is check that the time
is going where you think it is. Run the cProfile tool on the
code (with a smaller data set!) to see where the time is
being spent.
> Creating a C function and calling it from the code could improve the speed?
Yes, it could.
But it may not be necessary.
There are various add on tools that can drastically improve Python
efficiency, especially for math type functions so you might want to
check that nobody has already written what you need.
> If it is a reasonable solution to try decreasing the computational time
> how can I implement this C function?
If its already written in Python the easiest way might be to use Cython
to convert it into C. I'm no expert in Cython however, but others on
this list can help.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list