diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /util/string | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'util/string')
-rw-r--r-- | util/string/benchmark/ascii/main.cpp | 123 | ||||
-rw-r--r-- | util/string/benchmark/cast/main.cpp | 66 | ||||
-rw-r--r-- | util/string/benchmark/float_to_string/main.cpp | 253 | ||||
-rw-r--r-- | util/string/benchmark/float_to_string/metrics/main.py | 5 | ||||
-rw-r--r-- | util/string/benchmark/join/main.cpp | 95 | ||||
-rw-r--r-- | util/string/benchmark/join/metrics/main.py | 5 | ||||
-rw-r--r-- | util/string/benchmark/strip/main.cpp | 65 | ||||
-rw-r--r-- | util/string/benchmark/subst_global/main.cpp | 203 | ||||
-rw-r--r-- | util/string/benchmark/subst_global/metrics/main.py | 5 | ||||
-rw-r--r-- | util/string/cast.py | 27 | ||||
-rw-r--r-- | util/string/fuzzing/collapse/main.cpp | 12 | ||||
-rw-r--r-- | util/string/fuzzing/escape_c/main.cpp | 11 | ||||
-rw-r--r-- | util/string/fuzzing/strtod/main.cpp | 9 |
13 files changed, 0 insertions, 879 deletions
diff --git a/util/string/benchmark/ascii/main.cpp b/util/string/benchmark/ascii/main.cpp deleted file mode 100644 index 673047025d3..00000000000 --- a/util/string/benchmark/ascii/main.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#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; - } - }; - - struct TToLowerLookup { - char Table[256]; - - TToLowerLookup() { - for (size_t i : xrange(256)) { - Table[i] = AsciiToLower(i); - } - } - - char ToLower(char x) const noexcept { - 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)); - } - } -} - -Y_CPU_BENCHMARK(LookupAsciiToLower, iface) { - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(Singleton<TToLowerLookup>()->ToLower(j)); - } - } -} - -Y_CPU_BENCHMARK(LookupAsciiToLowerNoSingleton, iface) { - TToLowerLookup lookup; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - - for (int j = 0; j < 256; ++j) { - Y_DO_NOT_OPTIMIZE_AWAY(lookup.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/cast/main.cpp b/util/string/benchmark/cast/main.cpp deleted file mode 100644 index f604712ab6b..00000000000 --- a/util/string/benchmark/cast/main.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include <library/cpp/testing/benchmark/bench.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_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_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_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_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); - Y_DO_NOT_OPTIMIZE_AWAY(atoi(str1)); - } -} - -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_DO_NOT_OPTIMIZE_AWAY(atoi(str1234)); - } -} - -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/float_to_string/main.cpp b/util/string/benchmark/float_to_string/main.cpp deleted file mode 100644 index 1c7c0684a31..00000000000 --- a/util/string/benchmark/float_to_string/main.cpp +++ /dev/null @@ -1,253 +0,0 @@ -#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 { - TVector<TExample<T>> Examples; - - 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 { - TVector<TExample<T>> Examples; - - 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 diff --git a/util/string/benchmark/float_to_string/metrics/main.py b/util/string/benchmark/float_to_string/metrics/main.py deleted file mode 100644 index e9d4b7ac1d2..00000000000 --- a/util/string/benchmark/float_to_string/metrics/main.py +++ /dev/null @@ -1,5 +0,0 @@ -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/join/main.cpp b/util/string/benchmark/join/main.cpp deleted file mode 100644 index 1a8633d3a8d..00000000000 --- a/util/string/benchmark/join/main.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include <library/cpp/testing/benchmark/bench.h> - -#include <util/generic/function.h> -#include <util/generic/singleton.h> -#include <util/generic/vector.h> -#include <util/generic/xrange.h> -#include <util/random/fast.h> -#include <util/string/cast.h> -#include <util/string/join.h> - -namespace { - // This class assigns random values to variadic lists of variables of different types. - // It can be used to randomize a tuple via Apply() (arcadia version of std::apply). - class TRandomizer { - public: - TRandomizer(ui64 seed) - : Prng(seed) - { - } - - void Randomize(ui16& i) { - i = static_cast<ui16>(Prng.GenRand()); - } - - void Randomize(ui32& i) { - i = static_cast<ui32>(Prng.GenRand()); - } - - void Randomize(double& d) { - d = Prng.GenRandReal4() + Prng.Uniform(Max<ui16>()); - } - - void Randomize(TString& s) { - s = ::ToString(Prng.GenRand()); - } - - template <typename T, typename... TArgs> - void Randomize(T& t, TArgs&... args) { - Randomize(t); - Randomize(args...); - } - - private: - TFastRng<ui64> Prng; - }; - - template <size_t N, typename... T> - struct TExamplesHolder { - using TExamples = TVector<std::tuple<T...>>; - TExamples Examples; - - TExamplesHolder() - : Examples(N) - { - TRandomizer r{N * sizeof(typename TExamples::value_type) * 42}; - for (auto& x : Examples) { - Apply([&r](T&... t) { r.Randomize(t...); }, x); - } - } - }; - - 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_BENCHMARK(100, SS, TString, TString); -DEFINE_BENCHMARK(100, SSS, TString, TString, TString); -DEFINE_BENCHMARK(100, SSSSS, TString, TString, TString, TString, TString); - -DEFINE_BENCHMARK(100, ss, ui16, ui16); -DEFINE_BENCHMARK(100, SsS, TString, ui16, TString); -DEFINE_BENCHMARK(100, SsSsS, TString, ui16, TString, ui16, TString); - -DEFINE_BENCHMARK(100, ii, ui32, ui32); -DEFINE_BENCHMARK(100, SiS, TString, ui32, TString); -DEFINE_BENCHMARK(100, SiSiS, TString, ui32, TString, ui32, TString); - -DEFINE_BENCHMARK(100, dd, double, double); -DEFINE_BENCHMARK(100, SdS, TString, double, TString); -DEFINE_BENCHMARK(100, SdSdS, TString, double, TString, double, TString); - -#undef DEFINE_BENCHMARK diff --git a/util/string/benchmark/join/metrics/main.py b/util/string/benchmark/join/metrics/main.py deleted file mode 100644 index 1ed5014808f..00000000000 --- a/util/string/benchmark/join/metrics/main.py +++ /dev/null @@ -1,5 +0,0 @@ -import yatest.common as yc - - -def test_export_metrics(metrics): - metrics.set_benchmark(yc.execute_benchmark('util/string/benchmark/join/join', threads=8)) diff --git a/util/string/benchmark/strip/main.cpp b/util/string/benchmark/strip/main.cpp deleted file mode 100644 index 35a266e4f4d..00000000000 --- a/util/string/benchmark/strip/main.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include <library/cpp/testing/benchmark/bench.h> - -#include <util/string/strip.h> -#include <util/generic/xrange.h> - -static const TString SHORT_STRING = " foo "; -static const TString LONG_STRING = TString(200, ' ') + TString(200, 'f') + TString(200, ' '); - -Y_CPU_BENCHMARK(StripInPlaceShortNoChange, iface) { - TString s = "foo"; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - StripInPlace(s); - Y_DO_NOT_OPTIMIZE_AWAY(s); - } -} - -Y_CPU_BENCHMARK(StripInPlaceLongNoChange, iface) { - TString s = TString{200, 'f'}; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - StripInPlace(s); - Y_DO_NOT_OPTIMIZE_AWAY(s); - } -} - -Y_CPU_BENCHMARK(StripInPlaceShort, iface) { - TString s; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - s.assign(SHORT_STRING.begin(), SHORT_STRING.end()); - StripInPlace(s); - Y_DO_NOT_OPTIMIZE_AWAY(s); - } -} - -Y_CPU_BENCHMARK(StripInPlaceLong, iface) { - TString s; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - s.assign(LONG_STRING.begin(), LONG_STRING.end()); - StripInPlace(s); - Y_DO_NOT_OPTIMIZE_AWAY(s); - } -} - -Y_CPU_BENCHMARK(StripInPlaceShortMut, iface) { - TString s = SHORT_STRING; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - s.append(' '); - StripInPlace(s); - Y_DO_NOT_OPTIMIZE_AWAY(s); - } -} - -Y_CPU_BENCHMARK(StripInPlaceLongMut, iface) { - TString s = LONG_STRING; - for (const auto i : xrange(iface.Iterations())) { - Y_UNUSED(i); - s.append(100, ' '); - StripInPlace(s); - Y_DO_NOT_OPTIMIZE_AWAY(s); - } -} diff --git a/util/string/benchmark/subst_global/main.cpp b/util/string/benchmark/subst_global/main.cpp deleted file mode 100644 index e0decfa042e..00000000000 --- a/util/string/benchmark/subst_global/main.cpp +++ /dev/null @@ -1,203 +0,0 @@ -#include <library/cpp/testing/benchmark/bench.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 - }; - 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 - }; - 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 - }; - 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 - }; - 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 - }; - 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 - }; - 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 - }; - 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; \ - 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; \ - 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) diff --git a/util/string/benchmark/subst_global/metrics/main.py b/util/string/benchmark/subst_global/metrics/main.py deleted file mode 100644 index 62f2f3d76d2..00000000000 --- a/util/string/benchmark/subst_global/metrics/main.py +++ /dev/null @@ -1,5 +0,0 @@ -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/cast.py b/util/string/cast.py deleted file mode 100644 index 4787f6ef44c..00000000000 --- a/util/string/cast.py +++ /dev/null @@ -1,27 +0,0 @@ -print 'static const ui8 SAFE_LENS[4][15] = {' - - -def nb(n, b): - if n == 0: - return [0] - - digits = [] - - while n: - digits.append(int(n % b)) - n /= b - - return digits[::-1] - - -for p in (1, 2, 4, 8): - - def it1(): - for base in range(2, 17): - m = 2 ** (8 * p) - 1 - - yield len(nb(m, base)) - 1 - - print ' {0, 0, ' + ', '.join(str(x) for x in it1()) + '},' - -print '};' diff --git a/util/string/fuzzing/collapse/main.cpp b/util/string/fuzzing/collapse/main.cpp deleted file mode 100644 index e7b09f0f55d..00000000000 --- a/util/string/fuzzing/collapse/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include <util/string/strip.h> -#include <util/charset/wide.h> - -extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { - TUtf16String w((const wchar16*)data, size / 2); - Collapse(w); - - TString s((const char*)data, size); - CollapseInPlace(s); - - return 0; // Non-zero return values are reserved for future use. -} diff --git a/util/string/fuzzing/escape_c/main.cpp b/util/string/fuzzing/escape_c/main.cpp deleted file mode 100644 index 742126416a6..00000000000 --- a/util/string/fuzzing/escape_c/main.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include <util/generic/string.h> -#include <util/string/escape.h> - -extern "C" int LLVMFuzzerTestOneInput(const ui8* const data, const size_t size) { - const TString src(reinterpret_cast<const char*>(data), size); - const auto escaped = EscapeC(src); - const auto dst = UnescapeC(escaped); - - Y_VERIFY(src == dst); - return 0; -} diff --git a/util/string/fuzzing/strtod/main.cpp b/util/string/fuzzing/strtod/main.cpp deleted file mode 100644 index 50ea2a6afcb..00000000000 --- a/util/string/fuzzing/strtod/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include <util/string/cast.h> - -extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { - double res; - - TryFromString<double>((const char*)data, size, res); - - return 0; // Non-zero return values are reserved for future use. -} |