Small tests i share because why not
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

55 lignes
2.4 KiB

il y a 6 ans
il y a 6 ans
il y a 6 ans
il y a 6 ans
il y a 6 ans
  1. #include <chrono>
  2. #include <iostream>
  3. #include <string>
  4. #include <functional>
  5. #include "9float.hpp"
  6. using namespace std::chrono_literals;
  7. template<class T>
  8. void time_type(const T loop,T init,T incr ,const std::function<T(T,T)> lambda, std::string name)
  9. {
  10. T p;
  11. auto begin = std::chrono::high_resolution_clock::now();
  12. for(T i=0;i<loop;i+=1)
  13. {
  14. p=lambda(p,incr);
  15. p=lambda(p,incr);
  16. p=lambda(p,incr);
  17. p=lambda(p,incr);
  18. p=lambda(p,incr);
  19. p=lambda(p,incr);
  20. p=lambda(p,incr);
  21. p=lambda(p,incr);
  22. p=lambda(p,incr);
  23. p=lambda(p,incr);
  24. }
  25. auto end = std::chrono::high_resolution_clock::now();
  26. std::cout
  27. <<name
  28. <<" took "
  29. <<std::chrono::duration_cast<std::chrono::microseconds>(end-begin).count()
  30. <<"µs"
  31. <<std::endl;
  32. }
  33. int main()
  34. {
  35. time_type<int>(10000,1,1,[](int a,int b)->int {return a+b;}, "int +");
  36. time_type<int>(10000,20000,1,[](int a,int b)->int {return a-b;}, "int -");
  37. time_type<int>(10000,1,2,[](int a,int b)->int {return a*b;}, "int *");
  38. time_type<int>(10000,99999999,2,[](int a,int b)->int {return a/b;}, "int /");
  39. time_type<float>(10000,1,0.5,[](float a,float b)->float {return a+b;}, "float +");
  40. time_type<float>(10000,20000,1.14,[](float a,float b)->float {return a-b;}, "float -");
  41. time_type<float>(10000,1,1.25,[](float a,float b)->float {return a*b;}, "float *");
  42. time_type<float>(10000,99999999,1.25,[](float a,float b)->float {return a/b;}, "float /");
  43. time_type<double>(10000,1,0.5,[](double a,double b)->double {return a+b;}, "double +");
  44. time_type<double>(10000,20000,1.14,[](double a,double b)->double {return a-b;}, "double -");
  45. time_type<double>(10000,1,1.25,[](double a,double b)->double {return a*b;}, "double *");
  46. time_type<double>(10000,99999999,1.25,[](double a,double b)->double {return a/b;}, "double /");
  47. time_type<ninefloat::Q<int,16>>(10000,1,0.5,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a+b;}, "ninefloat::Q<int,16> +");
  48. time_type<ninefloat::Q<int,16>>(10000,20000,1.14,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a-b;}, "ninefloat::Q<int,16> -");
  49. time_type<ninefloat::Q<int,16>>(10000,1,1.25,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a*b;}, "ninefloat::Q<int,16> *");
  50. time_type<ninefloat::Q<int,16>>(10000,99999999,1.25,[](ninefloat::Q<int,16> a,ninefloat::Q<int,16> b)->ninefloat::Q<int,16> {return a/b;}, "ninefloat::Q<int,16> /");
  51. }