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.

47 lines
1.1 KiB

  1. #include <iostream>
  2. #include <StormEigen/Core>
  3. #include <StormEigen/Geometry>
  4. #include <bench/BenchTimer.h>
  5. using namespace StormEigen;
  6. template<typename Quat>
  7. STORMEIGEN_DONT_INLINE void quatmul_default(const Quat& a, const Quat& b, Quat& c)
  8. {
  9. c = a * b;
  10. }
  11. template<typename Quat>
  12. STORMEIGEN_DONT_INLINE void quatmul_novec(const Quat& a, const Quat& b, Quat& c)
  13. {
  14. c = internal::quat_product<0, Quat, Quat, typename Quat::Scalar, Aligned>::run(a,b);
  15. }
  16. template<typename Quat> void bench(const std::string& label)
  17. {
  18. int tries = 10;
  19. int rep = 1000000;
  20. BenchTimer t;
  21. Quat a(4, 1, 2, 3);
  22. Quat b(2, 3, 4, 5);
  23. Quat c;
  24. std::cout.precision(3);
  25. BENCH(t, tries, rep, quatmul_default(a,b,c));
  26. std::cout << label << " default " << 1e3*t.best(CPU_TIMER) << "ms \t" << 1e-6*double(rep)/(t.best(CPU_TIMER)) << " M mul/s\n";
  27. BENCH(t, tries, rep, quatmul_novec(a,b,c));
  28. std::cout << label << " novec " << 1e3*t.best(CPU_TIMER) << "ms \t" << 1e-6*double(rep)/(t.best(CPU_TIMER)) << " M mul/s\n";
  29. }
  30. int main()
  31. {
  32. bench<Quaternionf>("float ");
  33. bench<Quaterniond>("double");
  34. return 0;
  35. }