Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Subject: [PATCH] Fix
- ---
- Index: userver/universal/include/userver/utils/trivial_map.hpp
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/userver/universal/include/userver/utils/trivial_map.hpp b/userver/universal/include/userver/utils/trivial_map.hpp
- --- a/userver/universal/include/userver/utils/trivial_map.hpp (revision fee8d82e65bea2c716cbafa3a227ad70aef1cc1e)
- +++ b/userver/universal/include/userver/utils/trivial_map.hpp (date 1698090007795)
- @@ -713,6 +713,18 @@
- string, map.template DescribeByType<std::string>()));
- }
- +template <typename Selector, typename Keys, typename Values>
- +constexpr auto CaseWithArrays(Selector selector, const Keys& keys,
- + const Values& values) {
- + const auto size = std::size(keys);
- + UASSERT(size == std::size(values));
- + auto selector2 = selector.Case(keys[0], values[0]);
- + for (std::size_t i = 1; i < size; ++i) {
- + selector2 = selector2.Case(keys[i], values[i]);
- + }
- + return selector2;
- +}
- +
- namespace impl {
- // @brief Converts `value` to `std::string_view` using `map`. If `value` is not
- Index: userver/universal/src/utils/trivial_map_benchmark.cpp
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/userver/universal/src/utils/trivial_map_benchmark.cpp b/userver/universal/src/utils/trivial_map_benchmark.cpp
- --- a/userver/universal/src/utils/trivial_map_benchmark.cpp (revision fee8d82e65bea2c716cbafa3a227ad70aef1cc1e)
- +++ b/userver/universal/src/utils/trivial_map_benchmark.cpp (date 1698090007799)
- @@ -85,6 +85,32 @@
- .Case("aaaaaaaaaaaaaaaa_x9", 42);
- };
- +constexpr std::string_view kHugeTrivialBiMapKeys[] = {
- + "aaaaaaaaaaaaaaaa_hello", "aaaaaaaaaaaaaaaa_world", "aaaaaaaaaaaaaaaa_a",
- + "aaaaaaaaaaaaaaaa_b", "aaaaaaaaaaaaaaaa_c", "aaaaaaaaaaaaaaaa_d",
- + "aaaaaaaaaaaaaaaa_e", "aaaaaaaaaaaaaaaa_f", "aaaaaaaaaaaaaaaa_f1",
- + "aaaaaaaaaaaaaaaa_f2", "aaaaaaaaaaaaaaaa_f3", "aaaaaaaaaaaaaaaa_f4",
- + "aaaaaaaaaaaaaaaa_f5", "aaaaaaaaaaaaaaaa_f6", "aaaaaaaaaaaaaaaa_f7",
- + "aaaaaaaaaaaaaaaa_f8", "aaaaaaaaaaaaaaaa_f9", "aaaaaaaaaaaaaaaa_z",
- + "aaaaaaaaaaaaaaaa_z1", "aaaaaaaaaaaaaaaa_z2", "aaaaaaaaaaaaaaaa_z3",
- + "aaaaaaaaaaaaaaaa_z4", "aaaaaaaaaaaaaaaa_z5", "aaaaaaaaaaaaaaaa_z6",
- + "aaaaaaaaaaaaaaaa_z7", "aaaaaaaaaaaaaaaa_z8", "aaaaaaaaaaaaaaaa_z9",
- + "aaaaaaaaaaaaaaaa_x", "aaaaaaaaaaaaaaaa_x1", "aaaaaaaaaaaaaaaa_x2",
- + "aaaaaaaaaaaaaaaa_x3", "aaaaaaaaaaaaaaaa_x4", "aaaaaaaaaaaaaaaa_x5",
- + "aaaaaaaaaaaaaaaa_x6", "aaaaaaaaaaaaaaaa_x7", "aaaaaaaaaaaaaaaa_x8",
- + "aaaaaaaaaaaaaaaa_x9",
- +};
- +
- +constexpr int kHugeTrivialBiMapValues[] = {
- + 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 42, 42,
- + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
- +};
- +
- +constexpr utils::TrivialBiMap kHugeTrivialBiMapAlt = [](auto selector) {
- + return utils::CaseWithArrays(selector(), kHugeTrivialBiMapKeys,
- + kHugeTrivialBiMapValues);
- +};
- +
- const auto kHugeUnorderedMapping = std::unordered_map<std::string_view, int>{
- {"aaaaaaaaaaaaaaaa_hello", 1}, {"aaaaaaaaaaaaaaaa_world", 2},
- {"aaaaaaaaaaaaaaaa_a", 3}, {"aaaaaaaaaaaaaaaa_b", 4},
- @@ -347,6 +373,35 @@
- }
- BENCHMARK(MappingHugeTrivialBiMap);
- +void MappingHugeTrivialBiMapAlt(benchmark::State& state) {
- + auto hello = MyLaunder("aaaaaaaaaaaaaaaa_hello");
- + auto world = MyLaunder("aaaaaaaaaaaaaaaa_world");
- + auto a = MyLaunder("aaaaaaaaaaaaaaaa_a");
- + auto b = MyLaunder("aaaaaaaaaaaaaaaa_b");
- + auto c = MyLaunder("aaaaaaaaaaaaaaaa_c");
- +
- + auto d = MyLaunder("aaaaaaaaaaaaaaaa_d");
- + auto e = MyLaunder("aaaaaaaaaaaaaaaa_e");
- + auto f9 = MyLaunder("aaaaaaaaaaaaaaaa_f9");
- + auto z = MyLaunder("aaaaaaaaaaaaaaaa_z");
- + auto z9 = MyLaunder("aaaaaaaaaaaaaaaa_z9");
- +
- + for ([[maybe_unused]] auto _ : state) {
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(hello));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(world));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(a));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(b));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(c));
- +
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(d));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(e));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(f9));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(z));
- + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(z9));
- + }
- +}
- +BENCHMARK(MappingHugeTrivialBiMapAlt);
- +
- void MappingHugeUnordered(benchmark::State& state) {
- auto hello = MyLaunder("aaaaaaaaaaaaaaaa_hello");
- auto world = MyLaunder("aaaaaaaaaaaaaaaa_world");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement