aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/basicbenchmark.h
blob: 3fdc35732f02010997e1bcfd745854a60cdf69be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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