Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / libs / eigen / bench / basicbenchmark.h
blob3fdc35732f02010997e1bcfd745854a60cdf69be
2 #ifndef EIGEN_BENCH_BASICBENCH_H
3 #define EIGEN_BENCH_BASICBENCH_H
5 enum {LazyEval, EarlyEval, OmpEval};
7 template<int Mode, typename MatrixType>
8 void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations) __attribute__((noinline));
10 template<int Mode, typename MatrixType>
11 void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations)
13 for(int a = 0; a < iterations; a++)
15 if (Mode==LazyEval)
17 asm("#begin_bench_loop LazyEval");
18 if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
19 m = (I + 0.00005 * (m + m.lazy() * m)).eval();
21 else if (Mode==OmpEval)
23 asm("#begin_bench_loop OmpEval");
24 if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
25 m = (I + 0.00005 * (m + m.lazy() * m)).evalOMP();
27 else
29 asm("#begin_bench_loop EarlyEval");
30 if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize");
31 m = I + 0.00005 * (m + m * m);
33 asm("#end_bench_loop");
37 template<int Mode, typename MatrixType>
38 double benchBasic(const MatrixType& mat, int size, int tries) __attribute__((noinline));
40 template<int Mode, typename MatrixType>
41 double benchBasic(const MatrixType& mat, int iterations, int tries)
43 const int rows = mat.rows();
44 const int cols = mat.cols();
46 MatrixType I(rows,cols);
47 MatrixType m(rows,cols);
49 initMatrix_identity(I);
51 Eigen::BenchTimer timer;
52 for(uint t=0; t<tries; ++t)
54 initMatrix_random(m);
55 timer.start();
56 benchBasic_loop<Mode>(I, m, iterations);
57 timer.stop();
58 cerr << m;
60 return timer.value();
63 #endif // EIGEN_BENCH_BASICBENCH_H