diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/string/benchmark | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string/benchmark')
-rw-r--r-- | util/string/benchmark/ascii/main.cpp | 174 | ||||
-rw-r--r-- | util/string/benchmark/ascii/ya.make | 16 | ||||
-rw-r--r-- | util/string/benchmark/cast/main.cpp | 104 | ||||
-rw-r--r-- | util/string/benchmark/cast/ya.make | 16 | ||||
-rw-r--r-- | util/string/benchmark/float_to_string/main.cpp | 8 | ||||
-rw-r--r-- | util/string/benchmark/join/main.cpp | 26 | ||||
-rw-r--r-- | util/string/benchmark/subst_global/main.cpp | 4 | ||||
-rw-r--r-- | util/string/benchmark/ya.make | 4 |
8 files changed, 176 insertions, 176 deletions
diff --git a/util/string/benchmark/ascii/main.cpp b/util/string/benchmark/ascii/main.cpp index 673047025d..789300bde2 100644 --- a/util/string/benchmark/ascii/main.cpp +++ b/util/string/benchmark/ascii/main.cpp @@ -1,22 +1,22 @@ #include <library/cpp/testing/benchmark/bench.h> - -#include <util/generic/xrange.h> -#include <util/string/ascii.h> -#include <util/generic/bitmap.h> -#include <util/generic/singleton.h> - -namespace { - struct TUpperMap: public TBitMap<256> { - inline TUpperMap() noexcept { - for (unsigned i = 'A'; i <= 'Z'; ++i) { - Set((ui8)i); - } - } - - inline char ToLower(char x) const noexcept { - return Get((ui8)x) ? x + ('a' - 'A') : x; - } - }; + +#include <util/generic/xrange.h> +#include <util/string/ascii.h> +#include <util/generic/bitmap.h> +#include <util/generic/singleton.h> + +namespace { + struct TUpperMap: public TBitMap<256> { + inline TUpperMap() noexcept { + for (unsigned i = 'A'; i <= 'Z'; ++i) { + Set((ui8)i); + } + } + + inline char ToLower(char x) const noexcept { + return Get((ui8)x) ? x + ('a' - 'A') : x; + } + }; struct TToLowerLookup { char Table[256]; @@ -31,66 +31,66 @@ namespace { return Table[(ui8)x]; } }; -} - -static inline char FastAsciiToLower(char c) { - return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c; -} - -static inline char FastAsciiToLower2(char c) { - return c + ('a' - 'A') * (int)(c >= 'A' && c <= 'Z'); -} - -Y_CPU_BENCHMARK(AsciiToLower, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(AsciiToLower(j)); - } - } -} - -Y_CPU_BENCHMARK(AsciiToLowerChar, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(AsciiToLower((char)j)); - } - } -} - -Y_CPU_BENCHMARK(FastAsciiToLower, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(FastAsciiToLower(j)); - } - } -} - -Y_CPU_BENCHMARK(FastAsciiToLower2, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(FastAsciiToLower2(j)); - } - } -} - -Y_CPU_BENCHMARK(BitMapAsciiToLower, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(Singleton<TUpperMap>()->ToLower(j)); - } - } -} - +} + +static inline char FastAsciiToLower(char c) { + return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c; +} + +static inline char FastAsciiToLower2(char c) { + return c + ('a' - 'A') * (int)(c >= 'A' && c <= 'Z'); +} + +Y_CPU_BENCHMARK(AsciiToLower, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(AsciiToLower(j)); + } + } +} + +Y_CPU_BENCHMARK(AsciiToLowerChar, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(AsciiToLower((char)j)); + } + } +} + +Y_CPU_BENCHMARK(FastAsciiToLower, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(FastAsciiToLower(j)); + } + } +} + +Y_CPU_BENCHMARK(FastAsciiToLower2, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(FastAsciiToLower2(j)); + } + } +} + +Y_CPU_BENCHMARK(BitMapAsciiToLower, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(Singleton<TUpperMap>()->ToLower(j)); + } + } +} + Y_CPU_BENCHMARK(LookupAsciiToLower, iface) { for (const auto i : xrange(iface.Iterations())) { Y_UNUSED(i); @@ -112,12 +112,12 @@ Y_CPU_BENCHMARK(LookupAsciiToLowerNoSingleton, iface) { } } -Y_CPU_BENCHMARK(tolower, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(tolower(j)); - } - } -} +Y_CPU_BENCHMARK(tolower, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); + + for (int j = 0; j < 256; ++j) { + Y_DO_NOT_OPTIMIZE_AWAY(tolower(j)); + } + } +} diff --git a/util/string/benchmark/ascii/ya.make b/util/string/benchmark/ascii/ya.make index f95b9e0fa8..e973ba183a 100644 --- a/util/string/benchmark/ascii/ya.make +++ b/util/string/benchmark/ascii/ya.make @@ -1,9 +1,9 @@ Y_BENCHMARK() - -OWNER(pg) - -SRCS( - main.cpp -) - -END() + +OWNER(pg) + +SRCS( + main.cpp +) + +END() diff --git a/util/string/benchmark/cast/main.cpp b/util/string/benchmark/cast/main.cpp index f604712ab6..341c8a55d3 100644 --- a/util/string/benchmark/cast/main.cpp +++ b/util/string/benchmark/cast/main.cpp @@ -1,66 +1,66 @@ #include <library/cpp/testing/benchmark/bench.h> - -#include <util/string/cast.h> -#include <util/generic/xrange.h> - + +#include <util/string/cast.h> +#include <util/generic/xrange.h> + char str1[] = "1"; char str12[] = "12"; char str1234[] = "1234"; char str12345678[] = "12345678"; -Y_CPU_BENCHMARK(Parse_1, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); +Y_CPU_BENCHMARK(Parse_1, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str1, 1)); - } -} - -Y_CPU_BENCHMARK(Parse_12, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); + } +} + +Y_CPU_BENCHMARK(Parse_12, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str12, 2)); - } -} - -Y_CPU_BENCHMARK(Parse_1234, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); + } +} + +Y_CPU_BENCHMARK(Parse_1234, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str1234, 4)); - } -} - -Y_CPU_BENCHMARK(Parse_12345678, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); + } +} + +Y_CPU_BENCHMARK(Parse_12345678, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(FromString<ui32>(str12345678, 8)); - } -} - -//atoi -Y_CPU_BENCHMARK(Atoi_1, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); + } +} + +//atoi +Y_CPU_BENCHMARK(Atoi_1, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(atoi(str1)); - } -} - -Y_CPU_BENCHMARK(Atoi_12, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); + } +} + +Y_CPU_BENCHMARK(Atoi_12, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(atoi(str12)); - } -} - -Y_CPU_BENCHMARK(Atoi_1234, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); + } +} + +Y_CPU_BENCHMARK(Atoi_1234, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(atoi(str1234)); - } -} - -Y_CPU_BENCHMARK(Atoi_12345678, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); + } +} + +Y_CPU_BENCHMARK(Atoi_12345678, iface) { + for (const auto i : xrange(iface.Iterations())) { + Y_UNUSED(i); Y_DO_NOT_OPTIMIZE_AWAY(atoi(str12345678)); - } -} + } +} diff --git a/util/string/benchmark/cast/ya.make b/util/string/benchmark/cast/ya.make index f95b9e0fa8..e973ba183a 100644 --- a/util/string/benchmark/cast/ya.make +++ b/util/string/benchmark/cast/ya.make @@ -1,9 +1,9 @@ Y_BENCHMARK() - -OWNER(pg) - -SRCS( - main.cpp -) - -END() + +OWNER(pg) + +SRCS( + main.cpp +) + +END() diff --git a/util/string/benchmark/float_to_string/main.cpp b/util/string/benchmark/float_to_string/main.cpp index 1c7c0684a3..fed0de4b8f 100644 --- a/util/string/benchmark/float_to_string/main.cpp +++ b/util/string/benchmark/float_to_string/main.cpp @@ -37,8 +37,8 @@ namespace { TVector<TExample<T>> Examples; TExamplesHolder() - : Examples(N) - { + : Examples(N) + { TFastRng<ui64> prng{N * sizeof(T) * 42}; for (auto& x : Examples) { x.Value = prng.GenRandReal4() + prng.Uniform(Max<ui16>()); @@ -52,8 +52,8 @@ namespace { TVector<TExample<T>> Examples; TNearZeroExamplesHolder() - : Examples(N) - { + : Examples(N) + { TFastRng<ui64> prng{N * sizeof(T) * 42}; for (auto& x : Examples) { x.Value = prng.GenRandReal4(); diff --git a/util/string/benchmark/join/main.cpp b/util/string/benchmark/join/main.cpp index 1a8633d3a8..4742089bf8 100644 --- a/util/string/benchmark/join/main.cpp +++ b/util/string/benchmark/join/main.cpp @@ -34,7 +34,7 @@ namespace { s = ::ToString(Prng.GenRand()); } - template <typename T, typename... TArgs> + template <typename T, typename... TArgs> void Randomize(T& t, TArgs&... args) { Randomize(t); Randomize(args...); @@ -44,7 +44,7 @@ namespace { TFastRng<ui64> Prng; }; - template <size_t N, typename... T> + template <size_t N, typename... T> struct TExamplesHolder { using TExamples = TVector<std::tuple<T...>>; TExamples Examples; @@ -54,26 +54,26 @@ namespace { { TRandomizer r{N * sizeof(typename TExamples::value_type) * 42}; for (auto& x : Examples) { - Apply([&r](T&... t) { r.Randomize(t...); }, x); + Apply([&r](T&... t) { r.Randomize(t...); }, x); } } }; - template <typename... TArgs> + template <typename... TArgs> TString JoinTuple(std::tuple<TArgs...> t) { return Apply([](TArgs... x) -> TString { return Join("-", x...); }, t); } } -#define DEFINE_BENCHMARK(count, types, ...) \ - Y_CPU_BENCHMARK(Join_##count##_##types, iface) { \ - const auto& examples = Default<TExamplesHolder<count, __VA_ARGS__>>().Examples; \ - for (const auto i : xrange(iface.Iterations())) { \ - Y_UNUSED(i); \ - for (const auto e : examples) { \ - Y_DO_NOT_OPTIMIZE_AWAY(JoinTuple(e)); \ - } \ - } \ +#define DEFINE_BENCHMARK(count, types, ...) \ + Y_CPU_BENCHMARK(Join_##count##_##types, iface) { \ + const auto& examples = Default<TExamplesHolder<count, __VA_ARGS__>>().Examples; \ + for (const auto i : xrange(iface.Iterations())) { \ + Y_UNUSED(i); \ + for (const auto e : examples) { \ + Y_DO_NOT_OPTIMIZE_AWAY(JoinTuple(e)); \ + } \ + } \ } DEFINE_BENCHMARK(100, SS, TString, TString); diff --git a/util/string/benchmark/subst_global/main.cpp b/util/string/benchmark/subst_global/main.cpp index e0decfa042..000f5b47e0 100644 --- a/util/string/benchmark/subst_global/main.cpp +++ b/util/string/benchmark/subst_global/main.cpp @@ -154,7 +154,7 @@ namespace { for (const auto dummy : xrange(i.Iterations())) { \ Y_UNUSED(dummy); \ auto s = str; \ - NBench::Escape(s.data()); \ + NBench::Escape(s.data()); \ Y_DO_NOT_OPTIMIZE_AWAY(SubstGlobal(s, ToUnderlying(D::WHAT), ToUnderlying(D::WITH))); \ NBench::Clobber(); \ } \ @@ -167,7 +167,7 @@ namespace { for (const auto dummy : xrange(i.Iterations())) { \ Y_UNUSED(dummy); \ auto s = str; \ - NBench::Escape(s.data()); \ + NBench::Escape(s.data()); \ Y_DO_NOT_OPTIMIZE_AWAY(SubstGlobal(s, ToUnderlying(D::WHAT), ToUnderlying(D::WITH))); \ NBench::Clobber(); \ } \ diff --git a/util/string/benchmark/ya.make b/util/string/benchmark/ya.make index 266b53c7b3..4410edabaf 100644 --- a/util/string/benchmark/ya.make +++ b/util/string/benchmark/ya.make @@ -5,8 +5,8 @@ OWNER( SUBSCRIBER(g:util-subscribers) RECURSE( - ascii - cast + ascii + cast float_to_string float_to_string/metrics join |