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/ascii/main.cpp | |
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/ascii/main.cpp')
-rw-r--r-- | util/string/benchmark/ascii/main.cpp | 174 |
1 files changed, 87 insertions, 87 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)); + } + } +} |