benchFFT.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra. Eigen itself is part of the KDE project.
00003 //
00004 // Copyright (C) 2009 Mark Borgerding mark a borgerding net
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include <iostream>
00026 
00027 #include <bench/BenchUtil.h>
00028 #include <complex>
00029 #include <vector>
00030 #include <Eigen/Core>
00031 
00032 #include <unsupported/Eigen/FFT>
00033 
00034 using namespace Eigen;
00035 using namespace std;
00036 
00037 
00038 template <typename T>
00039 string nameof();
00040 
00041 template <> string nameof<float>() {return "float";}
00042 template <> string nameof<double>() {return "double";}
00043 template <> string nameof<long double>() {return "long double";}
00044 
00045 #ifndef TYPE
00046 #define TYPE float
00047 #endif
00048 
00049 #ifndef NFFT
00050 #define NFFT 1024
00051 #endif
00052 #ifndef NDATA
00053 #define NDATA 1000000
00054 #endif
00055 
00056 using namespace Eigen;
00057 
00058 template <typename T>
00059 void bench(int nfft,bool fwd,bool unscaled=false, bool halfspec=false)
00060 {
00061     typedef typename NumTraits<T>::Real Scalar;
00062     typedef typename std::complex<Scalar> Complex;
00063     int nits = NDATA/nfft;
00064     vector<T> inbuf(nfft);
00065     vector<Complex > outbuf(nfft);
00066     FFT< Scalar > fft;
00067 
00068     if (unscaled) {
00069         fft.SetFlag(fft.Unscaled);
00070         cout << "unscaled ";
00071     }
00072     if (halfspec) {
00073         fft.SetFlag(fft.HalfSpectrum);
00074         cout << "halfspec ";
00075     }
00076 
00077 
00078     std::fill(inbuf.begin(),inbuf.end(),0);
00079     fft.fwd( outbuf , inbuf);
00080 
00081     BenchTimer timer;
00082     timer.reset();
00083     for (int k=0;k<8;++k) {
00084         timer.start();
00085         if (fwd)
00086             for(int i = 0; i < nits; i++)
00087                 fft.fwd( outbuf , inbuf);
00088         else
00089             for(int i = 0; i < nits; i++)
00090                 fft.inv(inbuf,outbuf);
00091         timer.stop();
00092     }
00093 
00094     cout << nameof<Scalar>() << " ";
00095     double mflops = 5.*nfft*log2((double)nfft) / (1e6 * timer.value() / (double)nits );
00096     if ( NumTraits<T>::IsComplex ) {
00097         cout << "complex";
00098     }else{
00099         cout << "real   ";
00100         mflops /= 2;
00101     }
00102 
00103 
00104     if (fwd)
00105         cout << " fwd";
00106     else
00107         cout << " inv";
00108 
00109     cout << " NFFT=" << nfft << "  " << (double(1e-6*nfft*nits)/timer.value()) << " MS/s  " << mflops << "MFLOPS\n";
00110 }
00111 
00112 int main(int argc,char ** argv)
00113 {
00114     bench<complex<float> >(NFFT,true);
00115     bench<complex<float> >(NFFT,false);
00116     bench<float>(NFFT,true);
00117     bench<float>(NFFT,false);
00118     bench<float>(NFFT,false,true);
00119     bench<float>(NFFT,false,true,true);
00120 
00121     bench<complex<double> >(NFFT,true);
00122     bench<complex<double> >(NFFT,false);
00123     bench<double>(NFFT,true);
00124     bench<double>(NFFT,false);
00125     bench<complex<long double> >(NFFT,true);
00126     bench<complex<long double> >(NFFT,false);
00127     bench<long double>(NFFT,true);
00128     bench<long double>(NFFT,false);
00129     return 0;
00130 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:47