diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-04-16 09:11:59 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-04-16 09:11:59 +0000 |
commit | 25de1d521ca218e2b040739fea77a39e9fc543e9 (patch) | |
tree | 21521d8866cf1462dbd52c071cf369974c29650e /library/cpp/yson/node/benchmark/saveload.cpp | |
parent | bf444b8ed4d0f6bf17fd753e2cf88f9440012e87 (diff) | |
parent | 0a63d9ddc516f206f2b8745ce5e5dfa60190d755 (diff) | |
download | ydb-25de1d521ca218e2b040739fea77a39e9fc543e9.tar.gz |
Merge branch 'rightlib' into mergelibs-240416-0910
Diffstat (limited to 'library/cpp/yson/node/benchmark/saveload.cpp')
-rw-r--r-- | library/cpp/yson/node/benchmark/saveload.cpp | 57 |
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); |