source: pacpussensors/trunk/Vislab/lib3dv-1.2.0/lib3dv/eigen/bench/benchGeometry.cpp

Last change on this file was 136, checked in by ldecherf, 8 years ago

Doc

File size: 3.5 KB
Line 
1#include <iostream>
2#include <iomanip>
3#include <Eigen/Core>
4#include <Eigen/Geometry>
5#include <bench/BenchTimer.h>
6
7using namespace Eigen;
8using namespace std;
9
10#ifndef REPEAT
11#define REPEAT 1000000
12#endif
13
14enum func_opt
15{
16 TV,
17 TMATV,
18 TMATVMAT,
19};
20
21
22template <class res, class arg1, class arg2, int opt>
23struct func;
24
25template <class res, class arg1, class arg2>
26struct func<res, arg1, arg2, TV>
27{
28 static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 )
29 {
30 asm ("");
31 return a1 * a2;
32 }
33};
34
35template <class res, class arg1, class arg2>
36struct func<res, arg1, arg2, TMATV>
37{
38 static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 )
39 {
40 asm ("");
41 return a1.matrix() * a2;
42 }
43};
44
45template <class res, class arg1, class arg2>
46struct func<res, arg1, arg2, TMATVMAT>
47{
48 static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 )
49 {
50 asm ("");
51 return res(a1.matrix() * a2.matrix());
52 }
53};
54
55template <class func, class arg1, class arg2>
56struct test_transform
57{
58 static void run()
59 {
60 arg1 a1;
61 a1.setIdentity();
62 arg2 a2;
63 a2.setIdentity();
64
65 BenchTimer timer;
66 timer.reset();
67 for (int k=0; k<10; ++k)
68 {
69 timer.start();
70 for (int k=0; k<REPEAT; ++k)
71 a2 = func::run( a1, a2 );
72 timer.stop();
73 }
74 cout << setprecision(4) << fixed << timer.value() << "s " << endl;;
75 }
76};
77
78
79#define run_vec( op, scalar, mode, option, vsize ) \
80 std::cout << #scalar << "\t " << #mode << "\t " << #option << " " << #vsize " "; \
81 {\
82 typedef Transform<scalar, 3, mode, option> Trans;\
83 typedef Matrix<scalar, vsize, 1, option> Vec;\
84 typedef func<Vec,Trans,Vec,op> Func;\
85 test_transform< Func, Trans, Vec >::run();\
86 }
87
88#define run_trans( op, scalar, mode, option ) \
89 std::cout << #scalar << "\t " << #mode << "\t " << #option << " "; \
90 {\
91 typedef Transform<scalar, 3, mode, option> Trans;\
92 typedef func<Trans,Trans,Trans,op> Func;\
93 test_transform< Func, Trans, Trans >::run();\
94 }
95
96int main(int argc, char* argv[])
97{
98 cout << "vec = trans * vec" << endl;
99 run_vec(TV, float, Isometry, AutoAlign, 3);
100 run_vec(TV, float, Isometry, DontAlign, 3);
101 run_vec(TV, float, Isometry, AutoAlign, 4);
102 run_vec(TV, float, Isometry, DontAlign, 4);
103 run_vec(TV, float, Projective, AutoAlign, 4);
104 run_vec(TV, float, Projective, DontAlign, 4);
105 run_vec(TV, double, Isometry, AutoAlign, 3);
106 run_vec(TV, double, Isometry, DontAlign, 3);
107 run_vec(TV, double, Isometry, AutoAlign, 4);
108 run_vec(TV, double, Isometry, DontAlign, 4);
109 run_vec(TV, double, Projective, AutoAlign, 4);
110 run_vec(TV, double, Projective, DontAlign, 4);
111
112 cout << "vec = trans.matrix() * vec" << endl;
113 run_vec(TMATV, float, Isometry, AutoAlign, 4);
114 run_vec(TMATV, float, Isometry, DontAlign, 4);
115 run_vec(TMATV, double, Isometry, AutoAlign, 4);
116 run_vec(TMATV, double, Isometry, DontAlign, 4);
117
118 cout << "trans = trans1 * trans" << endl;
119 run_trans(TV, float, Isometry, AutoAlign);
120 run_trans(TV, float, Isometry, DontAlign);
121 run_trans(TV, double, Isometry, AutoAlign);
122 run_trans(TV, double, Isometry, DontAlign);
123 run_trans(TV, float, Projective, AutoAlign);
124 run_trans(TV, float, Projective, DontAlign);
125 run_trans(TV, double, Projective, AutoAlign);
126 run_trans(TV, double, Projective, DontAlign);
127
128 cout << "trans = trans1.matrix() * trans.matrix()" << endl;
129 run_trans(TMATVMAT, float, Isometry, AutoAlign);
130 run_trans(TMATVMAT, float, Isometry, DontAlign);
131 run_trans(TMATVMAT, double, Isometry, AutoAlign);
132 run_trans(TMATVMAT, double, Isometry, DontAlign);
133}
134
Note: See TracBrowser for help on using the repository browser.