Jakob Schwendner | 98798e9 | 2012-12-16 23:30:56 +0100 | [diff] [blame^] | 1 | #include <iostream> |
| 2 | #include <Eigen/Core> |
| 3 | #include <Eigen/Geometry> |
| 4 | #include <bench/BenchTimer.h> |
| 5 | using namespace Eigen; |
| 6 | |
| 7 | #ifndef REPEAT |
| 8 | #define REPEAT 1000000 |
| 9 | #endif |
| 10 | |
| 11 | enum func_opt |
| 12 | { |
| 13 | TV, |
| 14 | TMATRIXV |
| 15 | }; |
| 16 | |
| 17 | |
| 18 | template <class res, class arg1, class arg2, int opt> |
| 19 | struct func; |
| 20 | |
| 21 | template <class res, class arg1, class arg2> |
| 22 | struct func<res, arg1, arg2, TV> |
| 23 | { |
| 24 | static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) |
| 25 | { |
| 26 | asm (""); |
| 27 | return a1 * a2; |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | template <class res, class arg1, class arg2> |
| 32 | struct func<res, arg1, arg2, TMATRIXV> |
| 33 | { |
| 34 | static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) |
| 35 | { |
| 36 | asm (""); |
| 37 | return a1.matrix() * a2; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | template <class func, class arg1, class arg2> |
| 43 | struct test_transform |
| 44 | { |
| 45 | static void run() |
| 46 | { |
| 47 | arg1 a1; |
| 48 | a1.setIdentity(); |
| 49 | arg2 a2; |
| 50 | a2.setIdentity(); |
| 51 | |
| 52 | BenchTimer timer; |
| 53 | timer.reset(); |
| 54 | for (int k=0; k<10; ++k) |
| 55 | { |
| 56 | timer.start(); |
| 57 | for (int k=0; k<REPEAT; ++k) |
| 58 | a2 = func::run( a1, a2 ); |
| 59 | timer.stop(); |
| 60 | } |
| 61 | std::cout << timer.value() << "s " << (double(REPEAT)/timer.value())/(1024.*1024.*1024.) << " GFlops\n"; |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | #define run_test( op, scalar, mode, option, vsize ) \ |
| 67 | std::cout << #op << " " << #scalar << " " << #mode << " " << #option << " " << #vsize " "; \ |
| 68 | {\ |
| 69 | typedef Transform<scalar, 3, mode, option> Trans;\ |
| 70 | typedef Matrix<scalar, vsize, 1, option> Vec;\ |
| 71 | typedef func<Vec,Trans,Vec,op> Func;\ |
| 72 | test_transform< Func, Trans, Vec >::run();\ |
| 73 | } |
| 74 | |
| 75 | int main(int argc, char* argv[]) |
| 76 | { |
| 77 | run_test(TV, float, Isometry, AutoAlign, 3); |
| 78 | run_test(TV, float, Isometry, DontAlign, 3); |
| 79 | run_test(TV, float, Isometry, AutoAlign, 4); |
| 80 | run_test(TV, float, Isometry, DontAlign, 4); |
| 81 | |
| 82 | run_test(TMATRIXV, float, Isometry, AutoAlign, 4); |
| 83 | run_test(TMATRIXV, float, Isometry, DontAlign, 4); |
| 84 | } |