diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2016-09-18 12:42:15 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-11-02 15:12:04 +0100 |
| commit | 44861dcbfeee041223c4aac1ee075e92fa4daa01 (patch) | |
| tree | 6dfdfd9637846a7aedd71ace97d7d2ad366496d7 /eigen/bench/basicbenchmark.h | |
| parent | f3fe458b9e0a29a99a39d47d9a76dc18964b6fec (diff) | |
update
Diffstat (limited to 'eigen/bench/basicbenchmark.h')
| -rw-r--r-- | eigen/bench/basicbenchmark.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/eigen/bench/basicbenchmark.h b/eigen/bench/basicbenchmark.h new file mode 100644 index 0000000..3fdc357 --- /dev/null +++ b/eigen/bench/basicbenchmark.h @@ -0,0 +1,63 @@ + +#ifndef EIGEN_BENCH_BASICBENCH_H +#define EIGEN_BENCH_BASICBENCH_H + +enum {LazyEval, EarlyEval, OmpEval}; + +template<int Mode, typename MatrixType> +void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations) __attribute__((noinline)); + +template<int Mode, typename MatrixType> +void benchBasic_loop(const MatrixType& I, MatrixType& m, int iterations) +{ + for(int a = 0; a < iterations; a++) + { + if (Mode==LazyEval) + { + asm("#begin_bench_loop LazyEval"); + if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize"); + m = (I + 0.00005 * (m + m.lazy() * m)).eval(); + } + else if (Mode==OmpEval) + { + asm("#begin_bench_loop OmpEval"); + if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize"); + m = (I + 0.00005 * (m + m.lazy() * m)).evalOMP(); + } + else + { + asm("#begin_bench_loop EarlyEval"); + if (MatrixType::SizeAtCompileTime!=Eigen::Dynamic) asm("#fixedsize"); + m = I + 0.00005 * (m + m * m); + } + asm("#end_bench_loop"); + } +} + +template<int Mode, typename MatrixType> +double benchBasic(const MatrixType& mat, int size, int tries) __attribute__((noinline)); + +template<int Mode, typename MatrixType> +double benchBasic(const MatrixType& mat, int iterations, int tries) +{ + const int rows = mat.rows(); + const int cols = mat.cols(); + + MatrixType I(rows,cols); + MatrixType m(rows,cols); + + initMatrix_identity(I); + + Eigen::BenchTimer timer; + for(uint t=0; t<tries; ++t) + { + initMatrix_random(m); + timer.start(); + benchBasic_loop<Mode>(I, m, iterations); + timer.stop(); + cerr << m; + } + return timer.value(); +}; + +#endif // EIGEN_BENCH_BASICBENCH_H |
