[Tutor] improving speed using and recalling C functions

Danny Yoo dyoo at hashcollision.org
Fri Apr 11 23:00:23 CEST 2014

On Fri, Apr 11, 2014 at 1:01 PM, Gabriele Brambilla
<gb.gabrielebrambilla at gmail.com> wrote:
> Yes,
> but I want to make a C extension to run faster a function from
> scipy.interpolate (interp1d)

Just to emphasis: I believe your goal should be: "I want to make my
program fast."

Your goal should probably not be: "I want to write a C extension".
I'm not saying that writing a C extension is necessarily wrong, and it
may be that writing a C extension will make your program fast.  But
this approach may not be the easiest or most maintainable approach to
improving your program's performance.

Using C is not without its costs and risks.  As soon as you are in C
territory, the seat belts are off.  Just recall the craziness that
happened this week with regards to programs written in low-level
languages like C.  Explicitly: http://heartbleed.com.  If you are
writing with C, you have to be very, very delicate with your code.
Experts get it wrong, with severe consequences.

This is why the focus on C extensions to get speed disturbs me so
much: it assumes that C is a safe language to use.  It's not,
especially for beginners. We should strongly discourage low-level
languages unless there is some overriding concern.  For scientific
calculations like the ones you are doing, you should place a premium
on getting a right answer, and not just a fast answer.

More information about the Tutor mailing list