aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/pop_count/benchmark
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/pop_count/benchmark
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/pop_count/benchmark')
-rw-r--r--library/cpp/pop_count/benchmark/main.cpp52
-rw-r--r--library/cpp/pop_count/benchmark/ya.make14
2 files changed, 66 insertions, 0 deletions
diff --git a/library/cpp/pop_count/benchmark/main.cpp b/library/cpp/pop_count/benchmark/main.cpp
new file mode 100644
index 0000000000..41ea3c91cc
--- /dev/null
+++ b/library/cpp/pop_count/benchmark/main.cpp
@@ -0,0 +1,52 @@
+#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>
+
+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(PopCount_16, iface) {
+ DoRun([](ui16 x) {
+ return PopCount<ui16>(x);
+ },
+ iface);
+}
+
+Y_CPU_BENCHMARK(PopCount_32, iface) {
+ DoRun([](ui32 x) {
+ return PopCount<ui32>(x);
+ },
+ iface);
+}
+
+Y_CPU_BENCHMARK(PopCount_64, iface) {
+ DoRun([](ui64 x) {
+ return PopCount<ui64>(x);
+ },
+ iface);
+}
+
+#if !defined(_MSC_VER)
+Y_CPU_BENCHMARK(BUILTIN_64, iface) {
+ DoRun([](ui64 x) {
+ return __builtin_popcountll(x);
+ },
+ iface);
+}
+#endif
diff --git a/library/cpp/pop_count/benchmark/ya.make b/library/cpp/pop_count/benchmark/ya.make
new file mode 100644
index 0000000000..7fb54a519a
--- /dev/null
+++ b/library/cpp/pop_count/benchmark/ya.make
@@ -0,0 +1,14 @@
+OWNER(g:util)
+
+Y_BENCHMARK()
+
+PEERDIR(
+ util/draft
+ library/cpp/pop_count
+)
+
+SRCS(
+ main.cpp
+)
+
+END()