试试你的Numpy的FFT比Matlab的FFT快多少?
不试一下绝对想不到,按照FFTW的宣传他们比fftpack快三倍。Numpy用的是fftpack,Matlab用的是FFTW,为什么Numpy不用更快的FFTW呢?事实是这样吗?大家都测试测试。Matlab 用这个代码吧,改里面的n,可以试试10的幂次和2的幂次
n=10000;
a=rand(n,1);
tic;fft(a);toc;
tic;fft(a);toc
Python用这个代码吧,改里面的n (在IPython里跑了,懒得写timeit的代码)
import numpy as np
n=10000;
a=np.random.random((n,1))
%timeit np.fft.fft(a)
以下是我的机器的结果
Matlab:
n=10000;
Elapsed time is 0.000147 seconds.
n=100000;
Elapsed time is 0.001076 seconds.
n=1000000;
Elapsed time is 0.012248 seconds.
n=10000000;
Elapsed time is 0.301267 seconds.
n=2^10;
Elapsed time is 0.000087 seconds.
n=2^15;
Elapsed time is 0.000859 seconds.
n=2^20;
Elapsed time is 0.024616 seconds.
n=2^25;
Elapsed time is 0.787241 seconds.
Python:
n=10000;
10000 loops, best of 3: 40.5 us per loop
n=100000;
1000 loops, best of 3: 681 us per loop
n=1000000;
100 loops, best of 3: 7.66 ms per loop
n=10000000;
10 loops, best of 3: 76 ms per loop
n=2**10
100000 loops, best of 3: 7.75 us per loop
n=2**15
10000 loops, best of 3: 124 us per loop
n=2**20
100 loops, best of 3: 7.81 ms per loop
n=2**25
1 loops, best of 3: 245 ms per loop
结论:虽然不知道怎么回事,但是在我机器上Numpy的FFT速度完胜Matlab,和FFTW官网声称的速度相差甚远。请大家在自己的机器上测试一下FFT的速度。
没试过python 试了一下,ipython程序计时比较方便 n=10000, 10000 loops, best of 3: 65.5 μs per loop
n=100000, 1000 loops, best of 3: 1.28 ms per loop
n=1000000,100 loops, best of 3: 14.3 ms per loop
n=10000000,10 loops, best of 3: 148 ms per loop
本帖最后由 epistemer 于 2014-4-17 21:41 编辑
我的耗时比你的多啊,不过我是笔记本
matlab
n=10000;
Elapsed time is 0.250556 seconds.
Elapsed time is 0.000190 seconds.
n=100000;
Elapsed time is 0.043305 seconds.
Elapsed time is 0.002512 seconds.
页:
[1]