blob: 6e16c0331d84829cb1042837fbb8f3c1e8f10c4e [file] [log] [blame]
Jakob Schwendner98798e92012-12-16 23:30:56 +01001#include <iostream>
Jakob Schwendner22e67412012-12-17 09:33:22 +01002#include <iomanip>
Jakob Schwendner98798e92012-12-16 23:30:56 +01003#include <Eigen/Core>
4#include <Eigen/Geometry>
5#include <bench/BenchTimer.h>
Jakob Schwendner22e67412012-12-17 09:33:22 +01006
Jakob Schwendner98798e92012-12-16 23:30:56 +01007using namespace Eigen;
Jakob Schwendner22e67412012-12-17 09:33:22 +01008using namespace std;
Jakob Schwendner98798e92012-12-16 23:30:56 +01009
10#ifndef REPEAT
11#define REPEAT 1000000
12#endif
13
14enum func_opt
15{
16 TV,
Jakob Schwendner22e67412012-12-17 09:33:22 +010017 TMATV,
18 TMATVMAT,
Jakob Schwendner98798e92012-12-16 23:30:56 +010019};
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{
Christoph Hertzberg6300e8c2012-12-17 16:55:14 +010028 static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 )
Jakob Schwendner98798e92012-12-16 23:30:56 +010029 {
30 asm ("");
31 return a1 * a2;
32 }
33};
34
35template <class res, class arg1, class arg2>
Jakob Schwendner22e67412012-12-17 09:33:22 +010036struct func<res, arg1, arg2, TMATV>
Jakob Schwendner98798e92012-12-16 23:30:56 +010037{
Christoph Hertzberg6300e8c2012-12-17 16:55:14 +010038 static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 )
Jakob Schwendner98798e92012-12-16 23:30:56 +010039 {
40 asm ("");
41 return a1.matrix() * a2;
42 }
43};
44
Jakob Schwendner22e67412012-12-17 09:33:22 +010045template <class res, class arg1, class arg2>
46struct func<res, arg1, arg2, TMATVMAT>
47{
Christoph Hertzberg6300e8c2012-12-17 16:55:14 +010048 static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 )
Jakob Schwendner22e67412012-12-17 09:33:22 +010049 {
50 asm ("");
51 return res(a1.matrix() * a2.matrix());
52 }
53};
Jakob Schwendner98798e92012-12-16 23:30:56 +010054
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 }
Jakob Schwendner22e67412012-12-17 09:33:22 +010074 cout << setprecision(4) << fixed << timer.value() << "s " << endl;;
Jakob Schwendner98798e92012-12-16 23:30:56 +010075 }
76};
77
78
Jakob Schwendner22e67412012-12-17 09:33:22 +010079#define run_vec( op, scalar, mode, option, vsize ) \
80 std::cout << #scalar << "\t " << #mode << "\t " << #option << " " << #vsize " "; \
Jakob Schwendner98798e92012-12-16 23:30:56 +010081 {\
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
Jakob Schwendner22e67412012-12-17 09:33:22 +010088#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
Jakob Schwendner98798e92012-12-16 23:30:56 +010096int main(int argc, char* argv[])
97{
Jakob Schwendner22e67412012-12-17 09:33:22 +010098 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);
Jakob Schwendner98798e92012-12-16 23:30:56 +0100111
Jakob Schwendner22e67412012-12-17 09:33:22 +0100112 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);
Jakob Schwendner98798e92012-12-16 23:30:56 +0100133}
Jakob Schwendner22e67412012-12-17 09:33:22 +0100134