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.

63 lines
1.6 KiB

  1. #ifndef EIGEN_BENCH_BASICBENCH_H
  2. #define EIGEN_BENCH_BASICBENCH_H
  3. enum {LazyEval, EarlyEval, OmpEval};
  4. template<int Mode, typename MatrixType>
  5. void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations) __attribute__((noinline));
  6. template<int Mode, typename MatrixType>
  7. void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations)
  8. {
  9. for(int a = 0; a < iterations; a++)
  10. {
  11. if (Mode==LazyEval)
  12. {
  13. asm("#begin_bench_loop LazyEval");
  14. if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
  15. m = (I + 0.00005 * (m + m.lazy() * m)).eval();
  16. }
  17. else if (Mode==OmpEval)
  18. {
  19. asm("#begin_bench_loop OmpEval");
  20. if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
  21. m = (I + 0.00005 * (m + m.lazy() * m)).evalOMP();
  22. }
  23. else
  24. {
  25. asm("#begin_bench_loop EarlyEval");
  26. if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
  27. m = I + 0.00005 * (m + m * m);
  28. }
  29. asm("#end_bench_loop");
  30. }
  31. }
  32. template<int Mode, typename MatrixType>
  33. double benchBasic(const MatrixType& mat, int size, int tries) __attribute__((noinline));
  34. template<int Mode, typename MatrixType>
  35. double benchBasic(const MatrixType& mat, int iterations, int tries)
  36. {
  37. const int rows = mat.rows();
  38. const int cols = mat.cols();
  39. MatrixType I(rows,cols);
  40. MatrixType m(rows,cols);
  41. initMatrix_identity(I);
  42. Eigen::BenchTimer timer;
  43. for(uint t=0; t<tries; ++t)
  44. {
  45. initMatrix_random(m);
  46. timer.start();
  47. benchBasic_loop<Mode>(I, m, iterations);
  48. timer.stop();
  49. cerr << m;
  50. }
  51. return timer.value();
  52. };
  53. #endif // EIGEN_BENCH_BASICBENCH_H