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 
run_trans
#define run_trans(op, scalar, mode, option)
Definition: benchGeometry.cpp:88
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
timer
static BenchTimer timer
Definition: benchmark-blocking-sizes.cpp:31
func< res, arg1, arg2, TMATVMAT >::run
static EIGEN_DONT_INLINE res run(arg1 &a1, arg2 &a2)
Definition: benchGeometry.cpp:48
TV
@ TV
Definition: benchGeometry.cpp:16
run_vec
#define run_vec(op, scalar, mode, option, vsize)
Definition: benchGeometry.cpp:79
TMATVMAT
@ TMATVMAT
Definition: benchGeometry.cpp:18
res
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
Eigen::DontAlign
@ DontAlign
Definition: Constants.h:325
REPEAT
#define REPEAT
Definition: benchGeometry.cpp:11
Eigen::BenchTimer::value
double value(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:104
func_opt
func_opt
Definition: benchGeometry.cpp:14
align_3::a1
Point2 a1
Definition: testPose2.cpp:769
Eigen::Isometry
@ Isometry
Definition: Constants.h:457
Eigen::BenchTimer::start
void start()
Definition: BenchTimer.h:81
main
int main(int argc, char *argv[])
Definition: benchGeometry.cpp:96
test_transform
Definition: benchGeometry.cpp:56
Eigen::BenchTimer
Definition: BenchTimer.h:59
func< res, arg1, arg2, TV >::run
static EIGEN_DONT_INLINE res run(arg1 &a1, arg2 &a2)
Definition: benchGeometry.cpp:28
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
Eigen::AutoAlign
@ AutoAlign
Definition: Constants.h:323
Eigen::BenchTimer::reset
void reset()
Definition: BenchTimer.h:75
align_3::a2
Point2 a2
Definition: testPose2.cpp:770
std
Definition: BFloat16.h:88
BenchTimer.h
test_transform::run
static void run()
Definition: benchGeometry.cpp:58
Eigen::BenchTimer::stop
void stop()
Definition: BenchTimer.h:86
TMATV
@ TMATV
Definition: benchGeometry.cpp:17
func
Definition: benchGeometry.cpp:23
Projective
Definition: testAdaptAutoDiff.cpp:83
func< res, arg1, arg2, TMATV >::run
static EIGEN_DONT_INLINE res run(arg1 &a1, arg2 &a2)
Definition: benchGeometry.cpp:38
EIGEN_DONT_INLINE
#define EIGEN_DONT_INLINE
Definition: Macros.h:940


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:11