1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
|