aboutsummaryrefslogtreecommitdiffstats
path: root/util/random/benchmark/prng
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/random/benchmark/prng
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/random/benchmark/prng')
-rw-r--r--util/random/benchmark/prng/main.cpp123
-rw-r--r--util/random/benchmark/prng/metrics/main.py5
-rw-r--r--util/random/benchmark/prng/metrics/ya.make21
-rw-r--r--util/random/benchmark/prng/ya.make13
4 files changed, 162 insertions, 0 deletions
diff --git a/util/random/benchmark/prng/main.cpp b/util/random/benchmark/prng/main.cpp
new file mode 100644
index 0000000000..2c6279ff71
--- /dev/null
+++ b/util/random/benchmark/prng/main.cpp
@@ -0,0 +1,123 @@
+#include <library/cpp/testing/benchmark/bench.h>
+
+#include <util/random/entropy.h>
+#include <util/random/fast.h>
+#include <util/random/normal.h>
+#include <util/random/mersenne.h>
+#include <util/system/compiler.h>
+#include <util/generic/xrange.h>
+
+#include <random>
+
+// double part
+Y_CPU_BENCHMARK(Mersenne32_Double, p) {
+ TMersenne<ui32> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1());
+ }
+}
+
+Y_CPU_BENCHMARK(Mersenne64_Double, p) {
+ TMersenne<ui64> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1());
+ }
+}
+
+Y_CPU_BENCHMARK(Fast32_Double, p) {
+ TFastRng<ui32> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1());
+ }
+}
+
+Y_CPU_BENCHMARK(Fast64_Double, p) {
+ TFastRng<ui64> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRandReal1());
+ }
+}
+
+// integer part
+Y_CPU_BENCHMARK(mt19937_32, p) {
+ std::mt19937 mt;
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+
+ Y_DO_NOT_OPTIMIZE_AWAY(mt());
+ }
+}
+
+Y_CPU_BENCHMARK(mt19937_64, p) {
+ std::mt19937_64 mt;
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+
+ Y_DO_NOT_OPTIMIZE_AWAY(mt());
+ }
+}
+
+Y_CPU_BENCHMARK(Mersenne32_GenRand, p) {
+ TMersenne<ui32> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
+ }
+}
+
+Y_CPU_BENCHMARK(Mersenne64_GenRand, p) {
+ TMersenne<ui64> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
+ }
+}
+
+Y_CPU_BENCHMARK(Fast32_GenRand, p) {
+ TFastRng<ui32> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
+ }
+}
+
+Y_CPU_BENCHMARK(Fast64_GenRand, p) {
+ TFastRng<ui64> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(rng.GenRand());
+ }
+}
+
+Y_CPU_BENCHMARK(StlNormal, p) {
+ TFastRng<ui64> rng(Seed());
+ std::normal_distribution<double> d(1.0, 0.0);
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(d(rng));
+ }
+}
+
+Y_CPU_BENCHMARK(UtilNormal, p) {
+ TFastRng<ui64> rng(Seed());
+
+ for (auto i : xrange<size_t>(0, p.Iterations())) {
+ (void)i;
+ Y_DO_NOT_OPTIMIZE_AWAY(NormalDistribution<double>(rng, 1.0, 0.0));
+ }
+}
diff --git a/util/random/benchmark/prng/metrics/main.py b/util/random/benchmark/prng/metrics/main.py
new file mode 100644
index 0000000000..15b371fe75
--- /dev/null
+++ b/util/random/benchmark/prng/metrics/main.py
@@ -0,0 +1,5 @@
+import yatest.common as yc
+
+
+def test_export_metrics(metrics):
+ metrics.set_benchmark(yc.execute_benchmark('util/random/benchmark/prng/prng', threads=8))
diff --git a/util/random/benchmark/prng/metrics/ya.make b/util/random/benchmark/prng/metrics/ya.make
new file mode 100644
index 0000000000..1f56aac0bd
--- /dev/null
+++ b/util/random/benchmark/prng/metrics/ya.make
@@ -0,0 +1,21 @@
+OWNER(
+ yazevnul
+ g:util
+)
+SUBSCRIBER(g:util-subscribers)
+
+PY2TEST()
+
+SIZE(LARGE)
+
+TAG(
+ ya:force_sandbox
+ sb:intel_e5_2660v1
+ ya:fat
+)
+
+TEST_SRCS(main.py)
+
+DEPENDS(util/random/benchmark/prng)
+
+END()
diff --git a/util/random/benchmark/prng/ya.make b/util/random/benchmark/prng/ya.make
new file mode 100644
index 0000000000..976977014f
--- /dev/null
+++ b/util/random/benchmark/prng/ya.make
@@ -0,0 +1,13 @@
+OWNER(
+ yazevnul
+ g:util
+)
+SUBSCRIBER(g:util-subscribers)
+
+Y_BENCHMARK()
+
+SRCS(
+ main.cpp
+)
+
+END()