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