You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.5 KiB

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