2 #error Program requires FFTW3 headers to run. Check your environment settings and that DIANA_HAVE_FFTW3 is set
39 std::cout <<
"Benchmark FFT algorithms for different size windows.\n" << std::endl;
40 std::cout <<
"Options: " << std::endl;
41 std::cout <<
" -n : Number of runs per test." << std::endl;
42 std::cout <<
" -w : Add a window size to test. (Can specify multiple times)." << std::endl;
43 std::cout <<
" -o : Output to a root file." << std::endl;
44 std::cout <<
" -h : This helpful message." << std::endl;
50 double tDiff=difftime(t1,
t0);
51 int wrappedTime=((int)(tDiff/4294))*4294;
52 return (1.E3*cDiff/CLOCKS_PER_SEC)+1.E3*wrappedTime;
58 std::cout <<
"Benchmarking window size " << WinSize <<
" ... " << std::endl;
59 std::cout <<
"Running " << NRuns <<
" transforms per test ..." << std::endl;
65 bool compress =
false;
66 Diana::QVector X1(WinSize),X2(WinSize),X3(WinSize);
67 Diana::QVectorC Y1(compress ? WinSize/2+1 : WinSize),
68 Y2(compress ? WinSize/2+1 : WinSize),
70 for(
int j=0;j<WinSize;j++)
71 X1[j]=X2[j]=X3[j]=gRandom->Gaus();
73 clock_t c1 = ::clock();
74 time_t t1 = ::time(NULL);
75 Diana::QRealComplexFFTW3 *FFTW =
new Diana::QRealComplexFFTW3(WinSize);
76 FFTW->TransformToFreq(X1,Y1);
77 FFTW->TransformFromFreq(Y1,X1);
78 clock_t c2 = ::clock();
79 time_t t2 = ::time(NULL);
84 Diana::QRealComplexFFTGSL *GSL =
new Diana::QRealComplexFFTGSL(WinSize);
89 Diana::QFFTWRealComplexPlan FFTWForwardPlan = Diana::QFFTWRealComplexPlan::CreateForwardPlan(X3,Y3);
90 Diana::QFFTWRealComplexPlan FFTWBackwardPlan = Diana::QFFTWRealComplexPlan::CreateBackwardPlan(Y3,X3);
92 std::cout <<
"Running " << NRuns <<
" Forward Tests With GSL ..." << std::endl;
95 for(
int j=0;j<NRuns;j++)
96 GSL->TransformToFreq(X2,Y2,compress);
101 std::cout <<
"Running " << NRuns <<
" Forward Tests With FFTW ..." << std::endl;
104 for(
int j=0;j<NRuns;j++)
105 FFTW->TransformToFreq(X1,Y1,compress);
110 std::cout <<
"Running " << NRuns <<
" Forward Tests With FFTW Plan ..." << std::endl;
113 for(
int j=0;j<NRuns;j++)
114 FFTWForwardPlan.Execute();
119 std::cout <<
"Running " << NRuns <<
" Backward Tests With GSL ..." << std::endl;
122 for(
int j=0;j<NRuns;j++)
123 GSL->TransformFromFreq(Y2,X2,compress);
128 std::cout <<
"RUnning " << NRuns <<
" Backward Tests With FFTW ..." << std::endl;
131 for(
int j=0;j<NRuns;j++)
132 FFTW->TransformFromFreq(Y1,X1,compress);
137 std::cout <<
"Running " << NRuns <<
" Backward Tests With FFTW Plan ..." << std::endl;
140 for(
int j=0;j<NRuns;j++)
141 FFTWBackwardPlan.Execute();
147 std::cout <<
"GSL Prep:\t" << results.
fGSLPrepTime/1000 <<
"ms" << std::endl;
148 std::cout <<
"FFTW Prep:\t" << results.
fFFTWPrepTime/1000 <<
"ms" << std::endl;
150 std::cout << Form(
"GSL Forward:\t%.2f ms (%4.2f us/pulse)",
153 std::cout << Form(
"FFTW Forward:\t%.2f ms (%4.2f us/pulse)",
156 std::cout << Form(
"FFTW Forward Plan:\t%.2f ms (%4.2f us/pulse)",
159 Diana::QVectorC Diff=Y1-Y2;
160 std::cout <<
"MeanSqDif: "
161 << Diff.InterleavedVector().GetRMS(2*Diff.Size()) << std::endl;
163 std::cout << Form(
"GSL Backward:\t%.2f ms (%4.2f us/pulse)",
166 std::cout << Form(
"FFTW Backward:\t%.2f ms (%4.2f us/pulse)",
169 std::cout << Form(
"FFTW Backward Plan:\t%.2f ms (%4.2f us/pulse)",
173 Diana::QVector Diff2=X1-X2;
174 std::cout <<
"MeanSqDif: " << Diff2.GetRMS(Diff2.Size()) << std::endl;
180 std::cout << std::endl;
188 delete GSL;
delete FFTW;
192 int main(
int argc,
char *argv[]){
197 std::vector<int> windowSizes;
198 TFile *outFile = NULL;
202 while((c = getopt(argc,argv,
":n:w:o:h"))!=-1) {
208 windowSizes.push_back(atoi(
optarg));
212 outFile =
new TFile(
optarg,
"RECREATE");
213 tree =
new TTree(
"FFTBenchmark",
"FFT Benchmark Results");
220 std::cout <<
"Option -" << (char)
optopt <<
" requires an argument." << std::endl;
223 std::cout <<
"Unknown option: -" << (char)
optopt << std::endl;
228 std::cout <<
"Testing " << NRuns <<
" FFTs for window sizes: ";
229 for(
size_t i=0;i<windowSizes.size();i++)
230 std::cout << windowSizes[i] <<
" ";
231 std::cout << std::endl;
235 tree->Branch(
"NGSLTests",&NRuns,
"NGSLTests/I");
236 tree->Branch(
"NFFTWTests",&NRuns,
"NFFTWTests/I");
237 tree->Branch(
"WindowSize",&benchmarkData.
fWindowSize,
"WindowSize/I");
238 tree->Branch(
"GSLForwardTimePerPulse_us",&benchmarkData.
fGSLForwardTimePerPulse,
"GSLForwardTimePerPulse_us/D");
244 for(
size_t i=0;i<windowSizes.size();i++){
248 tree->Write(
"",TTree::kOverwrite);
int main(int argc, char *argv[])
double GetTime_ms(time_t t0, clock_t c0, time_t t1, clock_t c1)
void BenchmarkTransform(int NRuns, int WinSize, BenchmarkData &results)
double fFFTWForwardTimePerPulse
double fGSLForwardTimePerPulse
double fGSLBackwardTimePerPulse
double fFFTWForwardPlanTimePerPulse
double fFFTWBackwardPlanTimePerPulse
double fFFTWBackwardTimePerPulse