Advertisement
AntonyZhilin

Untitled

Oct 23rd, 2023
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. Subject: [PATCH] Fix
  2. ---
  3. Index: userver/universal/include/userver/utils/trivial_map.hpp
  4. IDEA additional info:
  5. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  6. <+>UTF-8
  7. ===================================================================
  8. diff --git a/userver/universal/include/userver/utils/trivial_map.hpp b/userver/universal/include/userver/utils/trivial_map.hpp
  9. --- a/userver/universal/include/userver/utils/trivial_map.hpp (revision fee8d82e65bea2c716cbafa3a227ad70aef1cc1e)
  10. +++ b/userver/universal/include/userver/utils/trivial_map.hpp (date 1698090007795)
  11. @@ -713,6 +713,18 @@
  12. string, map.template DescribeByType<std::string>()));
  13. }
  14.  
  15. +template <typename Selector, typename Keys, typename Values>
  16. +constexpr auto CaseWithArrays(Selector selector, const Keys& keys,
  17. + const Values& values) {
  18. + const auto size = std::size(keys);
  19. + UASSERT(size == std::size(values));
  20. + auto selector2 = selector.Case(keys[0], values[0]);
  21. + for (std::size_t i = 1; i < size; ++i) {
  22. + selector2 = selector2.Case(keys[i], values[i]);
  23. + }
  24. + return selector2;
  25. +}
  26. +
  27. namespace impl {
  28.  
  29. // @brief Converts `value` to `std::string_view` using `map`. If `value` is not
  30. Index: userver/universal/src/utils/trivial_map_benchmark.cpp
  31. IDEA additional info:
  32. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  33. <+>UTF-8
  34. ===================================================================
  35. diff --git a/userver/universal/src/utils/trivial_map_benchmark.cpp b/userver/universal/src/utils/trivial_map_benchmark.cpp
  36. --- a/userver/universal/src/utils/trivial_map_benchmark.cpp (revision fee8d82e65bea2c716cbafa3a227ad70aef1cc1e)
  37. +++ b/userver/universal/src/utils/trivial_map_benchmark.cpp (date 1698090007799)
  38. @@ -85,6 +85,32 @@
  39. .Case("aaaaaaaaaaaaaaaa_x9", 42);
  40. };
  41.  
  42. +constexpr std::string_view kHugeTrivialBiMapKeys[] = {
  43. + "aaaaaaaaaaaaaaaa_hello", "aaaaaaaaaaaaaaaa_world", "aaaaaaaaaaaaaaaa_a",
  44. + "aaaaaaaaaaaaaaaa_b", "aaaaaaaaaaaaaaaa_c", "aaaaaaaaaaaaaaaa_d",
  45. + "aaaaaaaaaaaaaaaa_e", "aaaaaaaaaaaaaaaa_f", "aaaaaaaaaaaaaaaa_f1",
  46. + "aaaaaaaaaaaaaaaa_f2", "aaaaaaaaaaaaaaaa_f3", "aaaaaaaaaaaaaaaa_f4",
  47. + "aaaaaaaaaaaaaaaa_f5", "aaaaaaaaaaaaaaaa_f6", "aaaaaaaaaaaaaaaa_f7",
  48. + "aaaaaaaaaaaaaaaa_f8", "aaaaaaaaaaaaaaaa_f9", "aaaaaaaaaaaaaaaa_z",
  49. + "aaaaaaaaaaaaaaaa_z1", "aaaaaaaaaaaaaaaa_z2", "aaaaaaaaaaaaaaaa_z3",
  50. + "aaaaaaaaaaaaaaaa_z4", "aaaaaaaaaaaaaaaa_z5", "aaaaaaaaaaaaaaaa_z6",
  51. + "aaaaaaaaaaaaaaaa_z7", "aaaaaaaaaaaaaaaa_z8", "aaaaaaaaaaaaaaaa_z9",
  52. + "aaaaaaaaaaaaaaaa_x", "aaaaaaaaaaaaaaaa_x1", "aaaaaaaaaaaaaaaa_x2",
  53. + "aaaaaaaaaaaaaaaa_x3", "aaaaaaaaaaaaaaaa_x4", "aaaaaaaaaaaaaaaa_x5",
  54. + "aaaaaaaaaaaaaaaa_x6", "aaaaaaaaaaaaaaaa_x7", "aaaaaaaaaaaaaaaa_x8",
  55. + "aaaaaaaaaaaaaaaa_x9",
  56. +};
  57. +
  58. +constexpr int kHugeTrivialBiMapValues[] = {
  59. + 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 42, 42,
  60. + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
  61. +};
  62. +
  63. +constexpr utils::TrivialBiMap kHugeTrivialBiMapAlt = [](auto selector) {
  64. + return utils::CaseWithArrays(selector(), kHugeTrivialBiMapKeys,
  65. + kHugeTrivialBiMapValues);
  66. +};
  67. +
  68. const auto kHugeUnorderedMapping = std::unordered_map<std::string_view, int>{
  69. {"aaaaaaaaaaaaaaaa_hello", 1}, {"aaaaaaaaaaaaaaaa_world", 2},
  70. {"aaaaaaaaaaaaaaaa_a", 3}, {"aaaaaaaaaaaaaaaa_b", 4},
  71. @@ -347,6 +373,35 @@
  72. }
  73. BENCHMARK(MappingHugeTrivialBiMap);
  74.  
  75. +void MappingHugeTrivialBiMapAlt(benchmark::State& state) {
  76. + auto hello = MyLaunder("aaaaaaaaaaaaaaaa_hello");
  77. + auto world = MyLaunder("aaaaaaaaaaaaaaaa_world");
  78. + auto a = MyLaunder("aaaaaaaaaaaaaaaa_a");
  79. + auto b = MyLaunder("aaaaaaaaaaaaaaaa_b");
  80. + auto c = MyLaunder("aaaaaaaaaaaaaaaa_c");
  81. +
  82. + auto d = MyLaunder("aaaaaaaaaaaaaaaa_d");
  83. + auto e = MyLaunder("aaaaaaaaaaaaaaaa_e");
  84. + auto f9 = MyLaunder("aaaaaaaaaaaaaaaa_f9");
  85. + auto z = MyLaunder("aaaaaaaaaaaaaaaa_z");
  86. + auto z9 = MyLaunder("aaaaaaaaaaaaaaaa_z9");
  87. +
  88. + for ([[maybe_unused]] auto _ : state) {
  89. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(hello));
  90. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(world));
  91. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(a));
  92. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(b));
  93. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(c));
  94. +
  95. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(d));
  96. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(e));
  97. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(f9));
  98. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(z));
  99. + benchmark::DoNotOptimize(kHugeTrivialBiMapAlt.TryFind(z9));
  100. + }
  101. +}
  102. +BENCHMARK(MappingHugeTrivialBiMapAlt);
  103. +
  104. void MappingHugeUnordered(benchmark::State& state) {
  105. auto hello = MyLaunder("aaaaaaaaaaaaaaaa_hello");
  106. auto world = MyLaunder("aaaaaaaaaaaaaaaa_world");
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement