aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/node/benchmark/saveload.cpp
diff options
context:
space:
mode:
authorionagamed <ionagamed@yandex-team.com>2024-04-15 10:18:45 +0300
committerionagamed <ionagamed@yandex-team.com>2024-04-15 10:28:06 +0300
commitc015541a60f8d93070c53511daaff81db730d194 (patch)
tree248d7d962c718e75801036109fdef147bc1880ed /library/cpp/yson/node/benchmark/saveload.cpp
parent7930380b354abe9969174901a4e8a730ab1d0906 (diff)
downloadydb-c015541a60f8d93070c53511daaff81db730d194.tar.gz
YT: Add NodeFromYsonStreamNonGreedy; use it in TNode::Load
В рамках 3547980204d51d6eba4c3b56989a916379526673
Diffstat (limited to 'library/cpp/yson/node/benchmark/saveload.cpp')
-rw-r--r--library/cpp/yson/node/benchmark/saveload.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/library/cpp/yson/node/benchmark/saveload.cpp b/library/cpp/yson/node/benchmark/saveload.cpp
new file mode 100644
index 0000000000..838075f2e4
--- /dev/null
+++ b/library/cpp/yson/node/benchmark/saveload.cpp
@@ -0,0 +1,57 @@
+#include <benchmark/benchmark.h>
+
+#include <library/cpp/yson/node/node_io.h>
+
+using namespace NYT;
+
+namespace {
+
+static NYT::TNode GenerateList(size_t size)
+{
+ NYT::TNode result = NYT::TNode::CreateList();
+
+ for (size_t i = 0; i < size; ++i) {
+ result.AsList().emplace_back(NYT::TNode("val"));
+ }
+
+ return result;
+}
+
+} // namespace
+
+static void BM_SaveLoadGreedy(benchmark::State& state, size_t size)
+{
+ auto list = GenerateList(size);
+
+ TString bytes;
+ TStringOutput outputStream{bytes};
+ NodeToYsonStream(list, &outputStream, ::NYson::EYsonFormat::Binary);
+
+ for (const auto& _ : state) {
+ TStringInput inputStream{bytes};
+ NodeFromYsonStream(&inputStream);
+ }
+}
+
+static void BM_SaveLoadNonGreedy(benchmark::State& state, size_t size)
+{
+ auto list = GenerateList(size);
+
+ TString bytes;
+ TStringOutput outputStream{bytes};
+ NodeToYsonStream(list, &outputStream, ::NYson::EYsonFormat::Binary);
+
+ for (const auto& _ : state) {
+ TStringInput inputStream{bytes};
+ NodeFromYsonStreamNonGreedy(&inputStream);
+ }
+}
+
+BENCHMARK_CAPTURE(BM_SaveLoadGreedy, greedy_10, 10ul);
+BENCHMARK_CAPTURE(BM_SaveLoadNonGreedy, non_greedy_10, 10ul);
+BENCHMARK_CAPTURE(BM_SaveLoadGreedy, greedy_100, 100ul);
+BENCHMARK_CAPTURE(BM_SaveLoadNonGreedy, non_greedy_100, 100ul);
+BENCHMARK_CAPTURE(BM_SaveLoadGreedy, greedy_1000, 1000ul);
+BENCHMARK_CAPTURE(BM_SaveLoadNonGreedy, non_greedy_1000, 1000ul);
+BENCHMARK_CAPTURE(BM_SaveLoadGreedy, greedy_10000, 10000ul);
+BENCHMARK_CAPTURE(BM_SaveLoadNonGreedy, non_greedy_10000, 10000ul);