Created
August 24, 2012 16:49
-
-
Save admsyn/3452792 to your computer and use it in GitHub Desktop.
Testing vDSP's FFT vs FFTW's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofMain.h" | |
#include "ofxFft.h" | |
#include <Accelerate/Accelerate.h> | |
#include <mach/mach_time.h> | |
double mach2ms(uint64_t time) | |
{ | |
mach_timebase_info_data_t timebase; | |
mach_timebase_info(&timebase); | |
return (double)time * (double)timebase.numer / (double)timebase.denom / 1e6; | |
} | |
int main() { | |
UInt32 min_log2N = 10; | |
UInt32 max_log2N = 20; | |
UInt32 max_N = (1 << max_log2N); | |
// Create re-useable vDSP bits | |
COMPLEX_SPLIT FFTData; | |
FFTData.realp = (float *) malloc(sizeof(float) * max_N/2); | |
FFTData.imagp = (float *) malloc(sizeof(float) * max_N/2); | |
float * hammingWindow = (float *) malloc(sizeof(float) * max_N); | |
float * A = (float *) malloc(sizeof(float) * max_N); | |
float * B = (float *) malloc(sizeof(float) * max_N); | |
FFTSetup FFTSetup = vDSP_create_fftsetup(max_log2N, kFFTRadix2); | |
// Create a fake signal | |
for(UInt32 i = 0; i < max_N; i++){ | |
A[i] = ofRandom(-1, 1); | |
} | |
for(UInt32 log2N = min_log2N; log2N < max_log2N; log2N++) | |
{ | |
UInt32 N = (1 << log2N); | |
// Prep vDSP | |
vDSP_hamm_window(hammingWindow, N, 0); | |
// Prep ofxFft | |
ofxFft * fft = ofxFft::create(N, OF_FFT_WINDOW_HAMMING, OF_FFT_FFTW); | |
uint64_t accel_start = mach_absolute_time(); | |
vDSP_vmul(A, 1, hammingWindow, 1, B, 1, N); // A -> hamming -> B | |
vDSP_ctoz((COMPLEX *) B, 2, &FFTData, 1, N/2); | |
vDSP_fft_zrip(FFTSetup, &FFTData, 1, log2N, kFFTDirection_Forward); | |
uint64_t accel_end = mach_absolute_time(); | |
uint64_t fftw_start = mach_absolute_time(); | |
fft->setSignal(A); | |
fft->getImaginary(); | |
uint64_t fftw_end = mach_absolute_time(); | |
cout | |
<< " N = " << N | |
<< " Accel: " << mach2ms(accel_end - accel_start) | |
<< " FFTW: " << mach2ms(fftw_end - fftw_start) << endl; | |
delete fft; | |
} | |
free(FFTData.realp); | |
free(FFTData.imagp); | |
free(hammingWindow); | |
free(A); | |
free(B); | |
vDSP_destroy_fftsetup(FFTSetup); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = 1024 Accel: 0.05265 FFTW: 0.026213 | |
N = 2048 Accel: 0.042565 FFTW: 0.049334 | |
N = 4096 Accel: 0.049206 FFTW: 0.082782 | |
N = 8192 Accel: 0.118918 FFTW: 0.173506 | |
N = 16384 Accel: 0.200201 FFTW: 0.371488 | |
N = 32768 Accel: 0.356826 FFTW: 1.01589 | |
N = 65536 Accel: 0.844955 FFTW: 1.79316 | |
N = 131072 Accel: 1.95759 FFTW: 3.99565 | |
N = 262144 Accel: 4.34179 FFTW: 9.87287 | |
N = 524288 Accel: 9.31858 FFTW: 19.6675 | |
Specs = Mid-2009 MBP, Core 2 Duo, 2.66GHz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment