aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/benchmark/sort
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 /util/generic/benchmark/sort
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/generic/benchmark/sort')
-rw-r--r--util/generic/benchmark/sort/main.cpp77
-rw-r--r--util/generic/benchmark/sort/ya.make10
2 files changed, 87 insertions, 0 deletions
diff --git a/util/generic/benchmark/sort/main.cpp b/util/generic/benchmark/sort/main.cpp
new file mode 100644
index 0000000000..d58f491f4d
--- /dev/null
+++ b/util/generic/benchmark/sort/main.cpp
@@ -0,0 +1,77 @@
+#include <library/cpp/testing/benchmark/bench.h>
+
+#include <util/generic/algorithm.h>
+#include <util/generic/vector.h>
+#include <util/generic/xrange.h>
+
+Y_CPU_BENCHMARK(Sort1, iface) {
+ TVector<int> x = {1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ Sort(x);
+ }
+}
+
+Y_CPU_BENCHMARK(Sort2, iface) {
+ TVector<int> x = {2, 1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ Sort(x);
+ }
+}
+
+Y_CPU_BENCHMARK(Sort4, iface) {
+ TVector<int> x = {4, 3, 2, 1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ Sort(x);
+ }
+}
+
+Y_CPU_BENCHMARK(Sort16, iface) {
+ TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ Sort(x);
+ }
+}
+
+Y_CPU_BENCHMARK(StableSort1, iface) {
+ TVector<int> x = {1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ StableSort(x);
+ }
+}
+
+Y_CPU_BENCHMARK(StableSort2, iface) {
+ TVector<int> x = {2, 1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ StableSort(x);
+ }
+}
+
+Y_CPU_BENCHMARK(StableSort4, iface) {
+ TVector<int> x = {4, 3, 2, 1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ StableSort(x);
+ }
+}
+
+Y_CPU_BENCHMARK(StableSort16, iface) {
+ TVector<int> x = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+
+ for (const auto i : xrange(iface.Iterations())) {
+ Y_UNUSED(i);
+ StableSort(x);
+ }
+}
diff --git a/util/generic/benchmark/sort/ya.make b/util/generic/benchmark/sort/ya.make
new file mode 100644
index 0000000000..7059abc3a4
--- /dev/null
+++ b/util/generic/benchmark/sort/ya.make
@@ -0,0 +1,10 @@
+Y_BENCHMARK()
+
+OWNER(g:util)
+SUBSCRIBER(g:util-subscribers)
+
+SRCS(
+ main.cpp
+)
+
+END()