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.

84 lines
2.1 KiB

  1. #include <iostream>
  2. #include <Eigen/Core>
  3. #include <bench/BenchUtil.h>
  4. using namespace Eigen;
  5. #ifndef REPEAT
  6. #define REPEAT 100000
  7. #endif
  8. #ifndef TRIES
  9. #define TRIES 20
  10. #endif
  11. typedef double Scalar;
  12. template <typename MatrixType>
  13. __attribute__ ((noinline)) void bench_reverse(const MatrixType& m)
  14. {
  15. int rows = m.rows();
  16. int cols = m.cols();
  17. int size = m.size();
  18. int repeats = (REPEAT*1000)/size;
  19. MatrixType a = MatrixType::Random(rows,cols);
  20. MatrixType b = MatrixType::Random(rows,cols);
  21. BenchTimer timerB, timerH, timerV;
  22. Scalar acc = 0;
  23. int r = internal::random<int>(0,rows-1);
  24. int c = internal::random<int>(0,cols-1);
  25. for (int t=0; t<TRIES; ++t)
  26. {
  27. timerB.start();
  28. for (int k=0; k<repeats; ++k)
  29. {
  30. asm("#begin foo");
  31. b = a.reverse();
  32. asm("#end foo");
  33. acc += b.coeff(r,c);
  34. }
  35. timerB.stop();
  36. }
  37. if (MatrixType::RowsAtCompileTime==Dynamic)
  38. std::cout << "dyn ";
  39. else
  40. std::cout << "fixed ";
  41. std::cout << rows << " x " << cols << " \t"
  42. << (timerB.value() * REPEAT) / repeats << "s "
  43. << "(" << 1e-6 * size*repeats/timerB.value() << " MFLOPS)\t";
  44. std::cout << "\n";
  45. // make sure the compiler does not optimize too much
  46. if (acc==123)
  47. std::cout << acc;
  48. }
  49. int main(int argc, char* argv[])
  50. {
  51. const int dynsizes[] = {4,6,8,16,24,32,49,64,128,256,512,900,0};
  52. std::cout << "size no sqrt standard";
  53. // #ifdef BENCH_GSL
  54. // std::cout << " GSL (standard + double + ATLAS) ";
  55. // #endif
  56. std::cout << "\n";
  57. for (uint i=0; dynsizes[i]>0; ++i)
  58. {
  59. bench_reverse(Matrix<Scalar,Dynamic,Dynamic>(dynsizes[i],dynsizes[i]));
  60. bench_reverse(Matrix<Scalar,Dynamic,1>(dynsizes[i]*dynsizes[i]));
  61. }
  62. // bench_reverse(Matrix<Scalar,2,2>());
  63. // bench_reverse(Matrix<Scalar,3,3>());
  64. // bench_reverse(Matrix<Scalar,4,4>());
  65. // bench_reverse(Matrix<Scalar,5,5>());
  66. // bench_reverse(Matrix<Scalar,6,6>());
  67. // bench_reverse(Matrix<Scalar,7,7>());
  68. // bench_reverse(Matrix<Scalar,8,8>());
  69. // bench_reverse(Matrix<Scalar,12,12>());
  70. // bench_reverse(Matrix<Scalar,16,16>());
  71. return 0;
  72. }