benchGeometry.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <Eigen/Core>
4 #include <Eigen/Geometry>
5 #include <bench/BenchTimer.h>
6 
7 using namespace Eigen;
8 using namespace std;
9 
10 #ifndef REPEAT
11 #define REPEAT 1000000
12 #endif
13 
15 {
16  TV,
19 };
20 
21 
22 template <class res, class arg1, class arg2, int opt>
23 struct func;
24 
25 template <class res, class arg1, class arg2>
26 struct 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 
35 template <class res, class arg1, class arg2>
36 struct 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 
45 template <class res, class arg1, class arg2>
46 struct 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 
55 template <class func, class arg1, class arg2>
57 {
58  static void run()
59  {
60  arg1 a1;
61  a1.setIdentity();
62  arg2 a2;
63  a2.setIdentity();
64 
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 
96 int 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;
133 }
134 
Point2 a1
Definition: testPose2.cpp:769
static EIGEN_DONT_INLINE res run(arg1 &a1, arg2 &a2)
double value(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:104
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Definition: BFloat16.h:88
int main(int argc, char *argv[])
#define EIGEN_DONT_INLINE
Definition: Macros.h:940
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
static EIGEN_DONT_INLINE res run(arg1 &a1, arg2 &a2)
#define run_trans(op, scalar, mode, option)
static EIGEN_DONT_INLINE res run(arg1 &a1, arg2 &a2)
#define REPEAT
Point2 a2
Definition: testPose2.cpp:770
static void run()
#define run_vec(op, scalar, mode, option, vsize)
func_opt
static BenchTimer timer


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:33:57