Speed problem even with C extension !

christophe grimault christophe.grimault at novagrid.com
Mon Feb 10 04:08:16 EST 2003


Hi all,

I have a few remarks / questions to submit to the guru's out there...
I've started to develop a specialized signal processing library, and I 
use python2 to have
stg like matlab : interpreter, dynamic completion, ease of programming when
relying on Numeric, ...

I also know that I have to do some C/ext to speed up things that are CPU 
intensive.
I did this and still, my pure C++ program still goes 5 to 15 times 
faster than my
mixed Python/C program.

A task example :

 0. Loop 100 times
    1. Fill a complex matrix (created with Numeric) with values,
    2. Do an FFT64,
    3. Swap a few values in the resulting array (fct foo() )
    4. Return the result,

In the Python/C version, for 1 and 2, Numeric is used, the call to the 
fft is done with Numeric FFT package, and for 3, a call to a Python/C 
foo() extension does the job. Only the outer loop and value return are 
Python.
In the pure C version, the fft is also from fftpack, so it is doing the 
same amount of job.

I would have expected a difference factor in the range from 1.3 to 2. Is 
it possible that the outer loop, the calling overhead (since the FFT64 
is a small FFT) of FFT and fct foo() are the reason.

I've also noticed that a few (if...elif...else) in between the five 
above steps contribute to slow down things even more. However they are 
very few of these.

Any opinion would be appreciated before I go deeper in my task !

Thanks,

C. Grimault









More information about the Python-list mailing list