You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.8 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Mark Borgerding mark a borgerding net
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include <iostream>
  10. #include <bench/BenchUtil.h>
  11. #include <complex>
  12. #include <vector>
  13. #include <Eigen/Core>
  14. #include <unsupported/Eigen/FFT>
  15. using namespace StormEigen;
  16. using namespace std;
  17. template <typename T>
  18. string nameof();
  19. template <> string nameof<float>() {return "float";}
  20. template <> string nameof<double>() {return "double";}
  21. template <> string nameof<long double>() {return "long double";}
  22. #ifndef TYPE
  23. #define TYPE float
  24. #endif
  25. #ifndef NFFT
  26. #define NFFT 1024
  27. #endif
  28. #ifndef NDATA
  29. #define NDATA 1000000
  30. #endif
  31. using namespace StormEigen;
  32. template <typename T>
  33. void bench(int nfft,bool fwd,bool unscaled=false, bool halfspec=false)
  34. {
  35. typedef typename NumTraits<T>::Real Scalar;
  36. typedef typename std::complex<Scalar> Complex;
  37. int nits = NDATA/nfft;
  38. vector<T> inbuf(nfft);
  39. vector<Complex > outbuf(nfft);
  40. FFT< Scalar > fft;
  41. if (unscaled) {
  42. fft.SetFlag(fft.Unscaled);
  43. cout << "unscaled ";
  44. }
  45. if (halfspec) {
  46. fft.SetFlag(fft.HalfSpectrum);
  47. cout << "halfspec ";
  48. }
  49. std::fill(inbuf.begin(),inbuf.end(),0);
  50. fft.fwd( outbuf , inbuf);
  51. BenchTimer timer;
  52. timer.reset();
  53. for (int k=0;k<8;++k) {
  54. timer.start();
  55. if (fwd)
  56. for(int i = 0; i < nits; i++)
  57. fft.fwd( outbuf , inbuf);
  58. else
  59. for(int i = 0; i < nits; i++)
  60. fft.inv(inbuf,outbuf);
  61. timer.stop();
  62. }
  63. cout << nameof<Scalar>() << " ";
  64. double mflops = 5.*nfft*log2((double)nfft) / (1e6 * timer.value() / (double)nits );
  65. if ( NumTraits<T>::IsComplex ) {
  66. cout << "complex";
  67. }else{
  68. cout << "real ";
  69. mflops /= 2;
  70. }
  71. if (fwd)
  72. cout << " fwd";
  73. else
  74. cout << " inv";
  75. cout << " NFFT=" << nfft << " " << (double(1e-6*nfft*nits)/timer.value()) << " MS/s " << mflops << "MFLOPS\n";
  76. }
  77. int main(int argc,char ** argv)
  78. {
  79. bench<complex<float> >(NFFT,true);
  80. bench<complex<float> >(NFFT,false);
  81. bench<float>(NFFT,true);
  82. bench<float>(NFFT,false);
  83. bench<float>(NFFT,false,true);
  84. bench<float>(NFFT,false,true,true);
  85. bench<complex<double> >(NFFT,true);
  86. bench<complex<double> >(NFFT,false);
  87. bench<double>(NFFT,true);
  88. bench<double>(NFFT,false);
  89. bench<complex<long double> >(NFFT,true);
  90. bench<complex<long double> >(NFFT,false);
  91. bench<long double>(NFFT,true);
  92. bench<long double>(NFFT,false);
  93. return 0;
  94. }