diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/generic/benchmark/string | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/generic/benchmark/string')
-rw-r--r-- | util/generic/benchmark/string/benchmarks.h | 188 | ||||
-rw-r--r-- | util/generic/benchmark/string/std_string.cpp | 8 | ||||
-rw-r--r-- | util/generic/benchmark/string/string.cpp | 8 | ||||
-rw-r--r-- | util/generic/benchmark/string/ya.make | 11 |
4 files changed, 215 insertions, 0 deletions
diff --git a/util/generic/benchmark/string/benchmarks.h b/util/generic/benchmark/string/benchmarks.h new file mode 100644 index 0000000000..e347d7ff47 --- /dev/null +++ b/util/generic/benchmark/string/benchmarks.h @@ -0,0 +1,188 @@ +#pragma once + +// Define BENCHMARK_PREFIX and BENCHMARKED_CLASS before including this file. + +#include <util/generic/xrange.h> + +#define Y_CPU_PREFIXED_BENCHMARK_HELPER(prefix, name, iface) Y_CPU_BENCHMARK(prefix##name, iface) +#define Y_CPU_PREFIXED_BENCHMARK(prefix, name, iface) Y_CPU_PREFIXED_BENCHMARK_HELPER(prefix, name, iface) +#define CONCATENATE3_HELPER(a, b, c) a##b##c +#define CONCATENATE3(a, b, c) CONCATENATE3_HELPER(a, b, c) + +namespace { + namespace CONCATENATE3(N, BENCHMARK_PREFIX, Benchmark) { + using TBenchmarkedClass = BENCHMARKED_CLASS; + + const auto defaultString = TBenchmarkedClass(); + const auto emptyString = TBenchmarkedClass(""); + const auto lengthOneString = TBenchmarkedClass("1"); + const auto length1KString = TBenchmarkedClass(1000, '1'); + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CreateDefault, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass(); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CreateFromEmptyLiteral, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass(""); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CreateFromLengthOneLiteral, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass("1"); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CreateLength1K, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass(1000, '1'); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyDefaultString, iface) { + const auto& sourceString = defaultString; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass(sourceString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyEmptyString, iface) { + const auto& sourceString = emptyString; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass(sourceString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyLengthOneString, iface) { + const auto& sourceString = lengthOneString; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass(sourceString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyLength1KString, iface) { + const auto& sourceString = length1KString; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto result = TBenchmarkedClass(sourceString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndUpdateLengthOneString, iface) { + const auto& sourceString = lengthOneString; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString[0] = '0'; + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndAppendDefaultString, iface) { + const auto& sourceString = defaultString; + const TBenchmarkedClass::size_type insertPosition = sourceString.size(); + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString.insert(insertPosition, 1, '0'); + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndAppendEmptyString, iface) { + const auto& sourceString = emptyString; + const TBenchmarkedClass::size_type insertPosition = sourceString.size(); + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString.insert(insertPosition, 1, '0'); + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndAppendLengthOneString, iface) { + const auto& sourceString = lengthOneString; + const TBenchmarkedClass::size_type insertPosition = sourceString.size(); + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString.insert(insertPosition, 1, '0'); + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndPrependLengthOneString, iface) { + const auto& sourceString = lengthOneString; + const TBenchmarkedClass::size_type insertPosition = 0; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString.insert(insertPosition, 1, '0'); + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndUpdateLength1KString, iface) { + const auto& sourceString = length1KString; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString[0] = '0'; + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndAppendLength1KString, iface) { + const auto& sourceString = length1KString; + const TBenchmarkedClass::size_type insertPosition = sourceString.size(); + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString.insert(insertPosition, 1, '0'); + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + + Y_CPU_PREFIXED_BENCHMARK(BENCHMARK_PREFIX, CopyAndPrependLength1KString, iface) { + const auto& sourceString = length1KString; + const TBenchmarkedClass::size_type insertPosition = 0; + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + auto targetString = TBenchmarkedClass(sourceString); + auto result = targetString.insert(insertPosition, 1, '0'); + Y_DO_NOT_OPTIMIZE_AWAY(targetString); + Y_DO_NOT_OPTIMIZE_AWAY(result); + } + } + } +} + +#undef CONCATENATE3 +#undef CONCATENATE3_HELPER +#undef Y_CPU_PREFIXED_BENCHMARK +#undef Y_CPU_PREFIXED_BENCHMARK_HELPER diff --git a/util/generic/benchmark/string/std_string.cpp b/util/generic/benchmark/string/std_string.cpp new file mode 100644 index 0000000000..cb10b4dc0c --- /dev/null +++ b/util/generic/benchmark/string/std_string.cpp @@ -0,0 +1,8 @@ +#include <library/cpp/testing/benchmark/bench.h> + +#include <string> + +#define BENCHMARK_PREFIX StdString +#define BENCHMARKED_CLASS std::string + +#include "benchmarks.h" diff --git a/util/generic/benchmark/string/string.cpp b/util/generic/benchmark/string/string.cpp new file mode 100644 index 0000000000..c634c204d8 --- /dev/null +++ b/util/generic/benchmark/string/string.cpp @@ -0,0 +1,8 @@ +#include <library/cpp/testing/benchmark/bench.h> + +#include <util/generic/string.h> + +#define BENCHMARK_PREFIX TString +#define BENCHMARKED_CLASS ::TString + +#include "benchmarks.h" diff --git a/util/generic/benchmark/string/ya.make b/util/generic/benchmark/string/ya.make new file mode 100644 index 0000000000..c2956de6a1 --- /dev/null +++ b/util/generic/benchmark/string/ya.make @@ -0,0 +1,11 @@ +Y_BENCHMARK() + +OWNER(g:util) +SUBSCRIBER(g:util-subscribers) + +SRCS( + string.cpp + std_string.cpp +) + +END() |