main.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <util/stream/output.h>
  2. #include <util/datetime/cputimer.h>
  3. #include <util/system/type_name.h>
  4. #include <library/cpp/pop_count/popcount.h>
  5. #include <library/cpp/testing/benchmark/bench.h>
  6. template <class F, class I>
  7. inline void DoRun(F&& f, I&& i) {
  8. const ui64 n = i.Iterations();
  9. for (ui64 j = 0; j < n; ++j) {
  10. Y_DO_NOT_OPTIMIZE_AWAY(f(j * (ui64)123456 + (ui64)1));
  11. }
  12. }
  13. Y_CPU_BENCHMARK(PopCount_8, iface) {
  14. DoRun([](ui8 x) {
  15. return PopCount<ui8>(x);
  16. },
  17. iface);
  18. }
  19. Y_CPU_BENCHMARK(PopCount_16, iface) {
  20. DoRun([](ui16 x) {
  21. return PopCount<ui16>(x);
  22. },
  23. iface);
  24. }
  25. Y_CPU_BENCHMARK(PopCount_32, iface) {
  26. DoRun([](ui32 x) {
  27. return PopCount<ui32>(x);
  28. },
  29. iface);
  30. }
  31. Y_CPU_BENCHMARK(PopCount_64, iface) {
  32. DoRun([](ui64 x) {
  33. return PopCount<ui64>(x);
  34. },
  35. iface);
  36. }
  37. #if !defined(_MSC_VER)
  38. Y_CPU_BENCHMARK(BUILTIN_64, iface) {
  39. DoRun([](ui64 x) {
  40. return __builtin_popcountll(x);
  41. },
  42. iface);
  43. }
  44. #endif