aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/benchmark
diff options
context:
space:
mode:
authoryazevnul <yazevnul@yandex-team.ru>2022-02-10 16:46:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:46 +0300
commit8cbc307de0221f84c80c42dcbe07d40727537e2c (patch)
tree625d5a673015d1df891e051033e9fcde5c7be4e5 /util/string/benchmark
parent30d1ef3941e0dc835be7609de5ebee66958f215a (diff)
downloadydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string/benchmark')
-rw-r--r--util/string/benchmark/float_to_string/main.cpp492
-rw-r--r--util/string/benchmark/float_to_string/metrics/main.py8
-rw-r--r--util/string/benchmark/float_to_string/metrics/ya.make26
-rw-r--r--util/string/benchmark/float_to_string/ya.make16
-rw-r--r--util/string/benchmark/subst_global/main.cpp384
-rw-r--r--util/string/benchmark/subst_global/metrics/main.py8
-rw-r--r--util/string/benchmark/subst_global/metrics/ya.make26
-rw-r--r--util/string/benchmark/subst_global/ya.make16
-rw-r--r--util/string/benchmark/ya.make20
9 files changed, 498 insertions, 498 deletions
diff --git a/util/string/benchmark/float_to_string/main.cpp b/util/string/benchmark/float_to_string/main.cpp
index 1c7c0684a3..c15b6009ad 100644
--- a/util/string/benchmark/float_to_string/main.cpp
+++ b/util/string/benchmark/float_to_string/main.cpp
@@ -1,253 +1,253 @@
#include <library/cpp/testing/benchmark/bench.h>
-
-#include <util/generic/singleton.h>
-#include <util/generic/vector.h>
-#include <util/generic/xrange.h>
-#include <util/generic/ymath.h>
-#include <util/random/fast.h>
-#include <util/string/cast.h>
-#include <util/string/printf.h>
-
-#include <limits>
-
-#include <cmath>
-
-/* Please be careful before making any decisions based on this benchmark.
- *
- * Only `Sprintf("%.<decimals>f", x)` and `FloatToString(x, PREC_POINT_DIGITS, decimals` produce
- * equal results in general case. However, results for cases when x \in [0, 1) must be equal for
- * both `Sprintf` and `FloatToString`.
- *
- * Read more about formatting in STL [1, 2] and Yandex Util formatting [3]
- *
- * [1] http://www.cplusplus.com/reference/cstdio/printf/
- * [2] http://en.cppreference.com/w/c/io/fprintf
- * [3] https://a.yandex-team.ru/arc/trunk/arcadia/util/string/cast.h?rev=2432660#L29
- */
-
-namespace {
- template <typename T>
- struct TExample {
- T Value{};
- int DigitsCount{};
- };
-
- template <typename T, size_t N>
- struct TExamplesHolder {
+
+#include <util/generic/singleton.h>
+#include <util/generic/vector.h>
+#include <util/generic/xrange.h>
+#include <util/generic/ymath.h>
+#include <util/random/fast.h>
+#include <util/string/cast.h>
+#include <util/string/printf.h>
+
+#include <limits>
+
+#include <cmath>
+
+/* Please be careful before making any decisions based on this benchmark.
+ *
+ * Only `Sprintf("%.<decimals>f", x)` and `FloatToString(x, PREC_POINT_DIGITS, decimals` produce
+ * equal results in general case. However, results for cases when x \in [0, 1) must be equal for
+ * both `Sprintf` and `FloatToString`.
+ *
+ * Read more about formatting in STL [1, 2] and Yandex Util formatting [3]
+ *
+ * [1] http://www.cplusplus.com/reference/cstdio/printf/
+ * [2] http://en.cppreference.com/w/c/io/fprintf
+ * [3] https://a.yandex-team.ru/arc/trunk/arcadia/util/string/cast.h?rev=2432660#L29
+ */
+
+namespace {
+ template <typename T>
+ struct TExample {
+ T Value{};
+ int DigitsCount{};
+ };
+
+ template <typename T, size_t N>
+ struct TExamplesHolder {
TVector<TExample<T>> Examples;
-
- TExamplesHolder()
+
+ TExamplesHolder()
: Examples(N)
{
- TFastRng<ui64> prng{N * sizeof(T) * 42};
- for (auto& x : Examples) {
- x.Value = prng.GenRandReal4() + prng.Uniform(Max<ui16>());
- x.DigitsCount = prng.Uniform(std::numeric_limits<T>::max_digits10 + 1);
- }
- }
- };
-
- template <typename T, size_t N>
- struct TNearZeroExamplesHolder {
+ TFastRng<ui64> prng{N * sizeof(T) * 42};
+ for (auto& x : Examples) {
+ x.Value = prng.GenRandReal4() + prng.Uniform(Max<ui16>());
+ x.DigitsCount = prng.Uniform(std::numeric_limits<T>::max_digits10 + 1);
+ }
+ }
+ };
+
+ template <typename T, size_t N>
+ struct TNearZeroExamplesHolder {
TVector<TExample<T>> Examples;
-
- TNearZeroExamplesHolder()
+
+ TNearZeroExamplesHolder()
: Examples(N)
{
- TFastRng<ui64> prng{N * sizeof(T) * 42};
- for (auto& x : Examples) {
- x.Value = prng.GenRandReal4();
- x.DigitsCount = prng.Uniform(std::numeric_limits<T>::max_digits10 + 1);
- }
- }
- };
-}
-
-static const char* FORMAT_FIXED[] = {
- "%.0f",
- "%.1f",
- "%.2f",
- "%.3f",
- "%.4f",
- "%.5f",
- "%.6f",
- "%.7f",
- "%.8f",
- "%.9f",
- "%.10f",
- "%.11f",
- "%.12f",
- "%.13f",
- "%.14f",
- "%.15f",
- "%.16f",
- "%.17f",
-};
-
-static const char* FORMAT_SIGNIFICANT[] = {
- "%.0g",
- "%.1g",
- "%.2g",
- "%.3g",
- "%.4g",
- "%.5g",
- "%.6g",
- "%.7g",
- "%.8g",
- "%.9g",
- "%.10g",
- "%.11g",
- "%.12g",
- "%.13g",
- "%.14g",
- "%.15g",
- "%.16g",
- "%.17g",
-};
-
-#define DEFINE_BENCHMARK(type, count) \
- Y_CPU_BENCHMARK(SprintfAuto_##type##_##count, iface) { \
- const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- /* this is in fact equal to Sprintf("%.6f", e.Value) and that is why it is faster */ \
- /* than FloatToString(e.Value) */ \
- Y_DO_NOT_OPTIMIZE_AWAY(Sprintf("%f", e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(FloatToStringAuto_##type##_##count, iface) { \
- const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(SprintfFixed_##type##_##count, iface) { \
- const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_FIXED[e.DigitsCount], e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(FloatToStringFixed_##type##_##count, iface) { \
- const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_NDIGITS, e.DigitsCount)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(SprintfSignificant_##type##_##count, iface) { \
- const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_SIGNIFICANT[e.DigitsCount], e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(FloatToStringSignificant_##type##_##count, iface) { \
- const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_POINT_DIGITS, e.DigitsCount)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(NearZeroSprintfAuto_##type##_##count, iface) { \
- const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- /* this is in fact equal to Sprintf("%.6f", e.Value) and that is why it is faster */ \
- /* than FloatToString(e.Value) */ \
- Y_DO_NOT_OPTIMIZE_AWAY(Sprintf("%f", e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(NearZeroFloatToStringAuto_##type##_##count, iface) { \
- const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(NearZeroSprintfFixed_##type##_##count, iface) { \
- const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_FIXED[e.DigitsCount], e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(NearZeroFloatToStringFixed_##type##_##count, iface) { \
- const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_NDIGITS, e.DigitsCount)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(NearZeroSprintfSignificant_##type##_##count, iface) { \
- const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_SIGNIFICANT[e.DigitsCount], e.Value)); \
- } \
- } \
- } \
- \
- Y_CPU_BENCHMARK(NearZeroFloatToStringSignificant_##type##_##count, iface) { \
- const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
- for (const auto i : xrange(iface.Iterations())) { \
- Y_UNUSED(i); \
- for (const auto e : examples) { \
- Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_POINT_DIGITS, e.DigitsCount)); \
- } \
- } \
- }
-
-DEFINE_BENCHMARK(float, 1);
-DEFINE_BENCHMARK(float, 2);
-DEFINE_BENCHMARK(float, 4);
-DEFINE_BENCHMARK(float, 8);
-DEFINE_BENCHMARK(float, 16);
-DEFINE_BENCHMARK(float, 32);
-DEFINE_BENCHMARK(float, 64);
-DEFINE_BENCHMARK(float, 128);
-DEFINE_BENCHMARK(float, 256);
-
-DEFINE_BENCHMARK(double, 1);
-DEFINE_BENCHMARK(double, 2);
-DEFINE_BENCHMARK(double, 4);
-DEFINE_BENCHMARK(double, 8);
-DEFINE_BENCHMARK(double, 16);
-DEFINE_BENCHMARK(double, 32);
-DEFINE_BENCHMARK(double, 64);
-DEFINE_BENCHMARK(double, 128);
-DEFINE_BENCHMARK(double, 256);
-
-#undef DEFINE_BENCHMARK
+ TFastRng<ui64> prng{N * sizeof(T) * 42};
+ for (auto& x : Examples) {
+ x.Value = prng.GenRandReal4();
+ x.DigitsCount = prng.Uniform(std::numeric_limits<T>::max_digits10 + 1);
+ }
+ }
+ };
+}
+
+static const char* FORMAT_FIXED[] = {
+ "%.0f",
+ "%.1f",
+ "%.2f",
+ "%.3f",
+ "%.4f",
+ "%.5f",
+ "%.6f",
+ "%.7f",
+ "%.8f",
+ "%.9f",
+ "%.10f",
+ "%.11f",
+ "%.12f",
+ "%.13f",
+ "%.14f",
+ "%.15f",
+ "%.16f",
+ "%.17f",
+};
+
+static const char* FORMAT_SIGNIFICANT[] = {
+ "%.0g",
+ "%.1g",
+ "%.2g",
+ "%.3g",
+ "%.4g",
+ "%.5g",
+ "%.6g",
+ "%.7g",
+ "%.8g",
+ "%.9g",
+ "%.10g",
+ "%.11g",
+ "%.12g",
+ "%.13g",
+ "%.14g",
+ "%.15g",
+ "%.16g",
+ "%.17g",
+};
+
+#define DEFINE_BENCHMARK(type, count) \
+ Y_CPU_BENCHMARK(SprintfAuto_##type##_##count, iface) { \
+ const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ /* this is in fact equal to Sprintf("%.6f", e.Value) and that is why it is faster */ \
+ /* than FloatToString(e.Value) */ \
+ Y_DO_NOT_OPTIMIZE_AWAY(Sprintf("%f", e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(FloatToStringAuto_##type##_##count, iface) { \
+ const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(SprintfFixed_##type##_##count, iface) { \
+ const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_FIXED[e.DigitsCount], e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(FloatToStringFixed_##type##_##count, iface) { \
+ const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_NDIGITS, e.DigitsCount)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(SprintfSignificant_##type##_##count, iface) { \
+ const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_SIGNIFICANT[e.DigitsCount], e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(FloatToStringSignificant_##type##_##count, iface) { \
+ const auto& examples = Default<TExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_POINT_DIGITS, e.DigitsCount)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(NearZeroSprintfAuto_##type##_##count, iface) { \
+ const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ /* this is in fact equal to Sprintf("%.6f", e.Value) and that is why it is faster */ \
+ /* than FloatToString(e.Value) */ \
+ Y_DO_NOT_OPTIMIZE_AWAY(Sprintf("%f", e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(NearZeroFloatToStringAuto_##type##_##count, iface) { \
+ const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(NearZeroSprintfFixed_##type##_##count, iface) { \
+ const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_FIXED[e.DigitsCount], e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(NearZeroFloatToStringFixed_##type##_##count, iface) { \
+ const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_NDIGITS, e.DigitsCount)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(NearZeroSprintfSignificant_##type##_##count, iface) { \
+ const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(Sprintf(FORMAT_SIGNIFICANT[e.DigitsCount], e.Value)); \
+ } \
+ } \
+ } \
+ \
+ Y_CPU_BENCHMARK(NearZeroFloatToStringSignificant_##type##_##count, iface) { \
+ const auto& examples = Default<TNearZeroExamplesHolder<type, count>>().Examples; \
+ for (const auto i : xrange(iface.Iterations())) { \
+ Y_UNUSED(i); \
+ for (const auto e : examples) { \
+ Y_DO_NOT_OPTIMIZE_AWAY(FloatToString(e.Value, PREC_POINT_DIGITS, e.DigitsCount)); \
+ } \
+ } \
+ }
+
+DEFINE_BENCHMARK(float, 1);
+DEFINE_BENCHMARK(float, 2);
+DEFINE_BENCHMARK(float, 4);
+DEFINE_BENCHMARK(float, 8);
+DEFINE_BENCHMARK(float, 16);
+DEFINE_BENCHMARK(float, 32);
+DEFINE_BENCHMARK(float, 64);
+DEFINE_BENCHMARK(float, 128);
+DEFINE_BENCHMARK(float, 256);
+
+DEFINE_BENCHMARK(double, 1);
+DEFINE_BENCHMARK(double, 2);
+DEFINE_BENCHMARK(double, 4);
+DEFINE_BENCHMARK(double, 8);
+DEFINE_BENCHMARK(double, 16);
+DEFINE_BENCHMARK(double, 32);
+DEFINE_BENCHMARK(double, 64);
+DEFINE_BENCHMARK(double, 128);
+DEFINE_BENCHMARK(double, 256);
+
+#undef DEFINE_BENCHMARK
diff --git a/util/string/benchmark/float_to_string/metrics/main.py b/util/string/benchmark/float_to_string/metrics/main.py
index e9d4b7ac1d..fdcfd71b0b 100644
--- a/util/string/benchmark/float_to_string/metrics/main.py
+++ b/util/string/benchmark/float_to_string/metrics/main.py
@@ -1,5 +1,5 @@
-import yatest.common as yc
-
-
-def test_export_metrics(metrics):
+import yatest.common as yc
+
+
+def test_export_metrics(metrics):
metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/float_to_string/float_to_string', threads=8))
diff --git a/util/string/benchmark/float_to_string/metrics/ya.make b/util/string/benchmark/float_to_string/metrics/ya.make
index 4b8c4cc07d..3081301d1d 100644
--- a/util/string/benchmark/float_to_string/metrics/ya.make
+++ b/util/string/benchmark/float_to_string/metrics/ya.make
@@ -1,21 +1,21 @@
-OWNER(
- yazevnul
+OWNER(
+ yazevnul
g:util
-)
+)
SUBSCRIBER(g:util-subscribers)
-
+
PY2TEST()
-
+
SIZE(LARGE)
-
-TAG(
+
+TAG(
ya:force_sandbox
- sb:intel_e5_2660v1
+ sb:intel_e5_2660v1
ya:fat
-)
-
+)
+
TEST_SRCS(main.py)
-
+
DEPENDS(util/string/benchmark/float_to_string)
-
-END()
+
+END()
diff --git a/util/string/benchmark/float_to_string/ya.make b/util/string/benchmark/float_to_string/ya.make
index 8136ad34f0..30955f3189 100644
--- a/util/string/benchmark/float_to_string/ya.make
+++ b/util/string/benchmark/float_to_string/ya.make
@@ -1,12 +1,12 @@
OWNER(yazevnul)
-
+
Y_BENCHMARK()
-
+
# to minimize allocations overhead
ALLOCATOR(B)
-
-SRCS(
- main.cpp
-)
-
-END()
+
+SRCS(
+ main.cpp
+)
+
+END()
diff --git a/util/string/benchmark/subst_global/main.cpp b/util/string/benchmark/subst_global/main.cpp
index e0decfa042..c9b14a5211 100644
--- a/util/string/benchmark/subst_global/main.cpp
+++ b/util/string/benchmark/subst_global/main.cpp
@@ -1,203 +1,203 @@
#include <library/cpp/testing/benchmark/bench.h>
-
-#include <util/generic/cast.h>
-#include <util/generic/singleton.h>
+
+#include <util/generic/cast.h>
+#include <util/generic/singleton.h>
#include <util/generic/string.h>
-#include <util/generic/xrange.h>
-#include <util/random/fast.h>
-#include <util/string/cast.h>
-#include <util/string/subst.h>
-
-namespace {
- template <size_t N, char What, char With>
- struct TNoMatches {
- enum : char {
- WHAT = What,
- WITH = With
- };
+#include <util/generic/xrange.h>
+#include <util/random/fast.h>
+#include <util/string/cast.h>
+#include <util/string/subst.h>
+
+namespace {
+ template <size_t N, char What, char With>
+ struct TNoMatches {
+ enum : char {
+ WHAT = What,
+ WITH = With
+ };
TString Str;
-
- TNoMatches() {
- for (const auto dummy : xrange(N)) {
- Y_UNUSED(dummy);
- Str += WHAT + 1;
- }
- }
- };
-
- template <size_t N, char What, char With>
- struct TOneMatchInTheBeginning {
- enum : char {
- WHAT = What,
- WITH = With
- };
+
+ TNoMatches() {
+ for (const auto dummy : xrange(N)) {
+ Y_UNUSED(dummy);
+ Str += WHAT + 1;
+ }
+ }
+ };
+
+ template <size_t N, char What, char With>
+ struct TOneMatchInTheBeginning {
+ enum : char {
+ WHAT = What,
+ WITH = With
+ };
TString Str;
-
- TOneMatchInTheBeginning() {
- if (!N) {
- return;
- }
-
- Str += WHAT;
- if (N > 1) {
- for (const auto dummy : xrange(N - 1)) {
- Y_UNUSED(dummy);
- Str += WHAT + 1;
- }
- }
- }
- };
-
- template <size_t N, char What, char With>
- struct TOneMatchInTheEnd {
- enum : char {
- WHAT = What,
- WITH = With
- };
+
+ TOneMatchInTheBeginning() {
+ if (!N) {
+ return;
+ }
+
+ Str += WHAT;
+ if (N > 1) {
+ for (const auto dummy : xrange(N - 1)) {
+ Y_UNUSED(dummy);
+ Str += WHAT + 1;
+ }
+ }
+ }
+ };
+
+ template <size_t N, char What, char With>
+ struct TOneMatchInTheEnd {
+ enum : char {
+ WHAT = What,
+ WITH = With
+ };
TString Str;
-
- TOneMatchInTheEnd() {
- if (!N) {
- return;
- }
-
- if (N > 1) {
- for (const auto dummy : xrange(N - 1)) {
- Y_UNUSED(dummy);
- Str += WHAT + 1;
- }
- }
- Str += WHAT;
- }
- };
-
- template <size_t N, char What, char With>
- struct TOneMatchInTheMiddle {
- enum : char {
- WHAT = What,
- WITH = With
- };
+
+ TOneMatchInTheEnd() {
+ if (!N) {
+ return;
+ }
+
+ if (N > 1) {
+ for (const auto dummy : xrange(N - 1)) {
+ Y_UNUSED(dummy);
+ Str += WHAT + 1;
+ }
+ }
+ Str += WHAT;
+ }
+ };
+
+ template <size_t N, char What, char With>
+ struct TOneMatchInTheMiddle {
+ enum : char {
+ WHAT = What,
+ WITH = With
+ };
TString Str;
-
- TOneMatchInTheMiddle() {
- if (!N) {
- return;
- }
-
- for (size_t i = 0; i < N / 2; ++i) {
- Str += WHAT + 1;
- }
- Str += WHAT;
- for (; Str.size() < N;) {
- Str += WHAT + 1;
- }
- }
- };
-
- template <size_t N, char What, char With>
- struct TFirstHalfMatches {
- enum : char {
- WHAT = What,
- WITH = With
- };
+
+ TOneMatchInTheMiddle() {
+ if (!N) {
+ return;
+ }
+
+ for (size_t i = 0; i < N / 2; ++i) {
+ Str += WHAT + 1;
+ }
+ Str += WHAT;
+ for (; Str.size() < N;) {
+ Str += WHAT + 1;
+ }
+ }
+ };
+
+ template <size_t N, char What, char With>
+ struct TFirstHalfMatches {
+ enum : char {
+ WHAT = What,
+ WITH = With
+ };
TString Str;
-
- TFirstHalfMatches() {
- for (size_t i = 0; i < N / 2; ++i) {
- Str += WHAT;
- }
- for (; Str.size() != N;) {
- Str += WHAT + 1;
- }
- }
- };
-
- template <size_t N, char What, char With>
- struct TSecondHalfMatches {
- enum : char {
- WHAT = What,
- WITH = With
- };
+
+ TFirstHalfMatches() {
+ for (size_t i = 0; i < N / 2; ++i) {
+ Str += WHAT;
+ }
+ for (; Str.size() != N;) {
+ Str += WHAT + 1;
+ }
+ }
+ };
+
+ template <size_t N, char What, char With>
+ struct TSecondHalfMatches {
+ enum : char {
+ WHAT = What,
+ WITH = With
+ };
TString Str;
-
- TSecondHalfMatches() {
- for (size_t i = 0; i < N / 2; ++i) {
- Str += WHAT + 1;
- }
- for (; Str.size() != N;) {
- Str += WHAT;
- }
- }
- };
-
- template <size_t N, size_t K, char What, char With>
- struct TEveryKth {
- enum : char {
- WHAT = What,
- WITH = With
- };
+
+ TSecondHalfMatches() {
+ for (size_t i = 0; i < N / 2; ++i) {
+ Str += WHAT + 1;
+ }
+ for (; Str.size() != N;) {
+ Str += WHAT;
+ }
+ }
+ };
+
+ template <size_t N, size_t K, char What, char With>
+ struct TEveryKth {
+ enum : char {
+ WHAT = What,
+ WITH = With
+ };
TString Str;
-
- TEveryKth() {
- TFastRng<ui64> prng{N * K * 101};
- for (size_t i = 0; i < N; ++i) {
- Str += (prng() % K) ? (WHAT + 1) : WHAT;
- }
- }
- };
-}
-
-#define DEFINE_BENCHMARK(type, N) \
- Y_CPU_BENCHMARK(type##_##N, i) { \
- using D = T##type<N, 'a', 'z'>; \
- const auto& str = Default<D>().Str; \
- for (const auto dummy : xrange(i.Iterations())) { \
- Y_UNUSED(dummy); \
- auto s = str; \
+
+ TEveryKth() {
+ TFastRng<ui64> prng{N * K * 101};
+ for (size_t i = 0; i < N; ++i) {
+ Str += (prng() % K) ? (WHAT + 1) : WHAT;
+ }
+ }
+ };
+}
+
+#define DEFINE_BENCHMARK(type, N) \
+ Y_CPU_BENCHMARK(type##_##N, i) { \
+ using D = T##type<N, 'a', 'z'>; \
+ const auto& str = Default<D>().Str; \
+ for (const auto dummy : xrange(i.Iterations())) { \
+ Y_UNUSED(dummy); \
+ auto s = str; \
NBench::Escape(s.data()); \
- Y_DO_NOT_OPTIMIZE_AWAY(SubstGlobal(s, ToUnderlying(D::WHAT), ToUnderlying(D::WITH))); \
- NBench::Clobber(); \
- } \
- }
-
-#define DEFINE_RNG_BENCHMARK(N, K) \
- Y_CPU_BENCHMARK(Random_##N##_##K, i) { \
- using D = TEveryKth<N, K, 'a', 'z'>; \
- const auto& str = Default<D>().Str; \
- for (const auto dummy : xrange(i.Iterations())) { \
- Y_UNUSED(dummy); \
- auto s = str; \
+ Y_DO_NOT_OPTIMIZE_AWAY(SubstGlobal(s, ToUnderlying(D::WHAT), ToUnderlying(D::WITH))); \
+ NBench::Clobber(); \
+ } \
+ }
+
+#define DEFINE_RNG_BENCHMARK(N, K) \
+ Y_CPU_BENCHMARK(Random_##N##_##K, i) { \
+ using D = TEveryKth<N, K, 'a', 'z'>; \
+ const auto& str = Default<D>().Str; \
+ for (const auto dummy : xrange(i.Iterations())) { \
+ Y_UNUSED(dummy); \
+ auto s = str; \
NBench::Escape(s.data()); \
- Y_DO_NOT_OPTIMIZE_AWAY(SubstGlobal(s, ToUnderlying(D::WHAT), ToUnderlying(D::WITH))); \
- NBench::Clobber(); \
- } \
- }
-
-DEFINE_BENCHMARK(NoMatches, 0)
-DEFINE_BENCHMARK(NoMatches, 1)
-DEFINE_BENCHMARK(NoMatches, 128)
-DEFINE_BENCHMARK(NoMatches, 4096)
-DEFINE_BENCHMARK(OneMatchInTheBeginning, 1)
-DEFINE_BENCHMARK(OneMatchInTheBeginning, 16)
-DEFINE_BENCHMARK(OneMatchInTheBeginning, 128)
-DEFINE_BENCHMARK(OneMatchInTheBeginning, 4096)
-DEFINE_BENCHMARK(OneMatchInTheEnd, 16)
-DEFINE_BENCHMARK(OneMatchInTheEnd, 128)
-DEFINE_BENCHMARK(OneMatchInTheEnd, 4096)
-DEFINE_BENCHMARK(OneMatchInTheMiddle, 16)
-DEFINE_BENCHMARK(OneMatchInTheMiddle, 128)
-DEFINE_BENCHMARK(OneMatchInTheMiddle, 4096)
-DEFINE_BENCHMARK(FirstHalfMatches, 16)
-DEFINE_BENCHMARK(FirstHalfMatches, 128)
-DEFINE_BENCHMARK(FirstHalfMatches, 4096)
-DEFINE_BENCHMARK(SecondHalfMatches, 16)
-DEFINE_BENCHMARK(SecondHalfMatches, 128)
-DEFINE_BENCHMARK(SecondHalfMatches, 4096)
-
-DEFINE_RNG_BENCHMARK(4096, 1)
-DEFINE_RNG_BENCHMARK(4096, 2)
-DEFINE_RNG_BENCHMARK(4096, 3)
-DEFINE_RNG_BENCHMARK(4096, 4)
-DEFINE_RNG_BENCHMARK(4096, 10)
-DEFINE_RNG_BENCHMARK(4096, 32)
-DEFINE_RNG_BENCHMARK(4096, 100)
+ Y_DO_NOT_OPTIMIZE_AWAY(SubstGlobal(s, ToUnderlying(D::WHAT), ToUnderlying(D::WITH))); \
+ NBench::Clobber(); \
+ } \
+ }
+
+DEFINE_BENCHMARK(NoMatches, 0)
+DEFINE_BENCHMARK(NoMatches, 1)
+DEFINE_BENCHMARK(NoMatches, 128)
+DEFINE_BENCHMARK(NoMatches, 4096)
+DEFINE_BENCHMARK(OneMatchInTheBeginning, 1)
+DEFINE_BENCHMARK(OneMatchInTheBeginning, 16)
+DEFINE_BENCHMARK(OneMatchInTheBeginning, 128)
+DEFINE_BENCHMARK(OneMatchInTheBeginning, 4096)
+DEFINE_BENCHMARK(OneMatchInTheEnd, 16)
+DEFINE_BENCHMARK(OneMatchInTheEnd, 128)
+DEFINE_BENCHMARK(OneMatchInTheEnd, 4096)
+DEFINE_BENCHMARK(OneMatchInTheMiddle, 16)
+DEFINE_BENCHMARK(OneMatchInTheMiddle, 128)
+DEFINE_BENCHMARK(OneMatchInTheMiddle, 4096)
+DEFINE_BENCHMARK(FirstHalfMatches, 16)
+DEFINE_BENCHMARK(FirstHalfMatches, 128)
+DEFINE_BENCHMARK(FirstHalfMatches, 4096)
+DEFINE_BENCHMARK(SecondHalfMatches, 16)
+DEFINE_BENCHMARK(SecondHalfMatches, 128)
+DEFINE_BENCHMARK(SecondHalfMatches, 4096)
+
+DEFINE_RNG_BENCHMARK(4096, 1)
+DEFINE_RNG_BENCHMARK(4096, 2)
+DEFINE_RNG_BENCHMARK(4096, 3)
+DEFINE_RNG_BENCHMARK(4096, 4)
+DEFINE_RNG_BENCHMARK(4096, 10)
+DEFINE_RNG_BENCHMARK(4096, 32)
+DEFINE_RNG_BENCHMARK(4096, 100)
diff --git a/util/string/benchmark/subst_global/metrics/main.py b/util/string/benchmark/subst_global/metrics/main.py
index 62f2f3d76d..8aa0501351 100644
--- a/util/string/benchmark/subst_global/metrics/main.py
+++ b/util/string/benchmark/subst_global/metrics/main.py
@@ -1,5 +1,5 @@
-import yatest.common as yc
-
-
-def test_export_metrics(metrics):
+import yatest.common as yc
+
+
+def test_export_metrics(metrics):
metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/subst_global/subst_global', threads=8))
diff --git a/util/string/benchmark/subst_global/metrics/ya.make b/util/string/benchmark/subst_global/metrics/ya.make
index d8c30ad460..73757bebcb 100644
--- a/util/string/benchmark/subst_global/metrics/ya.make
+++ b/util/string/benchmark/subst_global/metrics/ya.make
@@ -1,21 +1,21 @@
-OWNER(
- yazevnul
+OWNER(
+ yazevnul
g:util
-)
+)
SUBSCRIBER(g:util-subscribers)
-
+
PY2TEST()
-
+
SIZE(LARGE)
-
-TAG(
+
+TAG(
ya:force_sandbox
- sb:intel_e5_2660v1
+ sb:intel_e5_2660v1
ya:fat
-)
-
+)
+
TEST_SRCS(main.py)
-
+
DEPENDS(util/string/benchmark/subst_global)
-
-END()
+
+END()
diff --git a/util/string/benchmark/subst_global/ya.make b/util/string/benchmark/subst_global/ya.make
index 8136ad34f0..30955f3189 100644
--- a/util/string/benchmark/subst_global/ya.make
+++ b/util/string/benchmark/subst_global/ya.make
@@ -1,12 +1,12 @@
OWNER(yazevnul)
-
+
Y_BENCHMARK()
-
+
# to minimize allocations overhead
ALLOCATOR(B)
-
-SRCS(
- main.cpp
-)
-
-END()
+
+SRCS(
+ main.cpp
+)
+
+END()
diff --git a/util/string/benchmark/ya.make b/util/string/benchmark/ya.make
index 266b53c7b3..09b112034d 100644
--- a/util/string/benchmark/ya.make
+++ b/util/string/benchmark/ya.make
@@ -1,16 +1,16 @@
-OWNER(
+OWNER(
g:util
- yazevnul
-)
+ yazevnul
+)
SUBSCRIBER(g:util-subscribers)
-
-RECURSE(
+
+RECURSE(
ascii
cast
- float_to_string
- float_to_string/metrics
+ float_to_string
+ float_to_string/metrics
join
join/metrics
- subst_global
- subst_global/metrics
-)
+ subst_global
+ subst_global/metrics
+)