1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include <util/stream/output.h>
#include <util/datetime/cputimer.h>
#include <util/system/type_name.h>
#include <library/cpp/pop_count/popcount.h>
#include <library/cpp/testing/benchmark/bench.h>
#include <bit>
template <class F, class I>
inline void DoRun(F&& f, I&& i) {
const ui64 n = i.Iterations();
for (ui64 j = 0; j < n; ++j) {
Y_DO_NOT_OPTIMIZE_AWAY(f(j * (ui64)123456 + (ui64)1));
}
}
Y_CPU_BENCHMARK(PopCount_8, iface) {
DoRun([](ui8 x) {
return PopCount<ui8>(x);
},
iface);
}
Y_CPU_BENCHMARK(std_popcount_8, iface) {
DoRun([](ui8 x) {
return std::popcount<ui8>(x);
},
iface);
}
Y_CPU_BENCHMARK(PopCount_16, iface) {
DoRun([](ui16 x) {
return PopCount<ui16>(x);
},
iface);
}
Y_CPU_BENCHMARK(std_popcount_16, iface) {
DoRun([](ui16 x) {
return std::popcount<ui16>(x);
},
iface);
}
Y_CPU_BENCHMARK(PopCount_32, iface) {
DoRun([](ui32 x) {
return PopCount<ui32>(x);
},
iface);
}
Y_CPU_BENCHMARK(std_popcount_32, iface) {
DoRun([](ui32 x) {
return std::popcount<ui32>(x);
},
iface);
}
Y_CPU_BENCHMARK(PopCount_64, iface) {
DoRun([](ui64 x) {
return PopCount<ui64>(x);
},
iface);
}
Y_CPU_BENCHMARK(std_popcount_64, iface) {
DoRun([](ui64 x) {
return std::popcount<ui64>(x);
},
iface);
}
#if !defined(_MSC_VER)
Y_CPU_BENCHMARK(BUILTIN_64, iface) {
DoRun([](ui64 x) {
return __builtin_popcountll(x);
},
iface);
}
#endif
|