Improving FFT performance in Python Improving FFT performance in Python python python

Improving FFT performance in Python


You could certainly wrap whatever FFT implementation that you wanted to test using Cython or other like-minded tools that allow you to access external libraries.

GPU-based

If you're going to test FFT implementations, you might also take a look at GPU-based codes (if you have access to the proper hardware). There are several: reikna.fft, scikits.cuda.

CPU-based

There's also a CPU based python FFTW wrapper pyFFTW.

(There is pyFFTW3 as well, but it is not so actively maintained as pyFFTW, and it does not work with Python3. (source))

I don't have experience with any of these. It's probably going to fall to you to do some digging around and benchmark different codes for your particular application if speed is important to you.


For a test detailed at https://gist.github.com/fnielsen/99b981b9da34ae3d5035 I find that scipy.fftpack performs fine compared to my simple application of pyfftw via pyfftw.interfaces.scipy_fftpack, except for data with a length corresponding to a prime number.

There seems to be some setup cost associated with evoking pyfftw.interfaces.scipy_fftpack.fft the first time. The second time it is faster. Numpy's and scipy's fftpack with a prime number performs terribly for the size of data I tried. CZT is faster in that case. Some months ago an issue was put up at Scipy's Github about the problem, see https://github.com/scipy/scipy/issues/4288

20000 prime=False  padded_fft : 0.003116   numpy_fft : 0.003502   scipy_fft : 0.001538         czt : 0.035041    fftw_fft : 0.004007------------------------------------------------------------20011 prime=True  padded_fft : 0.001070   numpy_fft : 1.263672   scipy_fft : 0.875641         czt : 0.033139    fftw_fft : 0.009980------------------------------------------------------------21803 prime=True  padded_fft : 0.001076   numpy_fft : 1.510341   scipy_fft : 1.043572         czt : 0.035129    fftw_fft : 0.011463------------------------------------------------------------21804 prime=False  padded_fft : 0.001108   numpy_fft : 0.004672   scipy_fft : 0.001620         czt : 0.033854    fftw_fft : 0.005075------------------------------------------------------------21997 prime=True  padded_fft : 0.000940   numpy_fft : 1.534876   scipy_fft : 1.058001         czt : 0.034321    fftw_fft : 0.012839------------------------------------------------------------32768 prime=False  padded_fft : 0.001222   numpy_fft : 0.002410   scipy_fft : 0.000925         czt : 0.039275    fftw_fft : 0.005714------------------------------------------------------------


The pyFFTW3 package is inferior compared to the pyFFTW library, at least implementation wise. Since they both wrap the FFTW3 library I guess speed should be the same.

https://pypi.python.org/pypi/pyFFTW