Project
Loading...
Searching...
No Matches
benchmark_TableBuilder.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#include <benchmark/benchmark.h>
15
16using namespace o2::framework;
17using namespace o2::soa;
18
19static void BM_TableBuilderOverhead(benchmark::State& state)
20{
21 using namespace o2::framework;
22
23 for (auto _ : state) {
24 TableBuilder builder;
25 [[maybe_unused]] auto rowWriter = builder.persist<float, float, float>({"x", "y", "z"});
26 auto table = builder.finalize();
27 }
28}
29
30BENCHMARK(BM_TableBuilderOverhead);
31
32static void BM_TableBuilderScalar(benchmark::State& state)
33{
34 using namespace o2::framework;
35 for (auto _ : state) {
36 TableBuilder builder;
37 auto rowWriter = builder.persist<float>({"x"});
38 for (auto i = 0; i < state.range(0); ++i) {
39 rowWriter(0, 0.f);
40 }
41 auto table = builder.finalize();
42 }
43}
44
45BENCHMARK(BM_TableBuilderScalar)->Arg(1 << 21);
46BENCHMARK(BM_TableBuilderScalar)->Range(8, 8 << 16);
47
48static void BM_TableBuilderScalarReserved(benchmark::State& state)
49{
50 using namespace o2::framework;
51 for (auto _ : state) {
52 TableBuilder builder;
53 auto rowWriter = builder.persist<float>({"x"});
54 builder.reserve(o2::framework::pack<float>{}, state.range(0));
55 for (auto i = 0; i < state.range(0); ++i) {
56 rowWriter(0, 0.f);
57 }
58 auto table = builder.finalize();
59 }
60}
61
62BENCHMARK(BM_TableBuilderScalarReserved)->Arg(1 << 21);
63BENCHMARK(BM_TableBuilderScalarReserved)->Range(8, 8 << 16);
64
65static void BM_TableBuilderScalarPresized(benchmark::State& state)
66{
67 using namespace o2::framework;
68 for (auto _ : state) {
69 TableBuilder builder;
70 auto rowWriter = builder.preallocatedPersist<float>({"x"}, state.range(0));
71 for (auto i = 0; i < state.range(0); ++i) {
72 rowWriter(0, 0.f);
73 }
74 auto table = builder.finalize();
75 }
76}
77
78BENCHMARK(BM_TableBuilderScalarPresized)->Arg(1 << 20);
79BENCHMARK(BM_TableBuilderScalarPresized)->Range(8, 8 << 16);
80
81static void BM_TableBuilderScalarBulk(benchmark::State& state)
82{
83 using namespace o2::framework;
84 auto chunkSize = state.range(0) / 256;
85 std::vector<float> buffer(chunkSize, 0.); // We assume data is chunked in blocks 256th of the total size
86 for (auto _ : state) {
87 TableBuilder builder;
88 auto bulkWriter = builder.bulkPersist<float>({"x"}, state.range(0));
89 for (auto i = 0; i < state.range(0) / chunkSize; ++i) {
90 bulkWriter(0, chunkSize, buffer.data());
91 }
92 auto table = builder.finalize();
93 }
94}
95
96BENCHMARK(BM_TableBuilderScalarBulk)->Range(256, 1 << 20);
97
98static void BM_TableBuilderSimple(benchmark::State& state)
99{
100 using namespace o2::framework;
101 for (auto _ : state) {
102 TableBuilder builder;
103 auto rowWriter = builder.persist<float, float, float>({"x", "y", "z"});
104 for (auto i = 0; i < state.range(0); ++i) {
105 rowWriter(0, 0.f, 0.f, 0.f);
106 }
107 auto table = builder.finalize();
108 }
109}
110
111BENCHMARK(BM_TableBuilderSimple)->Arg(1 << 20);
112
113static void BM_TableBuilderSimple2(benchmark::State& state)
114{
115 using namespace o2::framework;
116 for (auto _ : state) {
117 TableBuilder builder;
118 auto rowWriter = builder.persist<float, float, float>({"x", "y", "z"});
119 for (auto i = 0; i < state.range(0); ++i) {
120 rowWriter(0, 0.f, 0.f, 0.f);
121 }
122 auto table = builder.finalize();
123 }
124}
125
126BENCHMARK(BM_TableBuilderSimple2)->Range(8, 8 << 16);
127
128namespace test
129{
133} // namespace test
134
135using TestVectors = o2::soa::InPlaceTable<"TST/0"_h, test::X, test::Y, test::Z>;
136
137static void BM_TableBuilderSoA(benchmark::State& state)
138{
139 using namespace o2::framework;
140 for (auto _ : state) {
141 TableBuilder builder;
142 auto rowWriter = builder.cursor<TestVectors>();
143 for (auto i = 0; i < state.range(0); ++i) {
144 rowWriter(0, 0.f, 0.f, 0.f);
145 }
146 auto table = builder.finalize();
147 }
148}
149
150BENCHMARK(BM_TableBuilderSoA)->Range(8, 8 << 16);
151
152static void BM_TableBuilderComplex(benchmark::State& state)
153{
154 using namespace o2::framework;
155 for (auto _ : state) {
156 TableBuilder builder;
157 auto rowWriter = builder.persist<int, float, std::string, bool>({"x", "y", "s", "b"});
158 for (auto i = 0; i < state.range(0); ++i) {
159 rowWriter(0, 0, 0., "foo", true);
160 }
161 auto table = builder.finalize();
162 }
163}
164
165BENCHMARK(BM_TableBuilderComplex)->Range(8, 8 << 16);
166
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_)
Definition ASoA.h:2314
benchmark::State & state
int32_t i
BENCHMARK_MAIN()
BENCHMARK(BM_TableBuilderOverhead)
auto bulkPersist(std::array< char const *, NCOLUMNS > const &columnNames, size_t nRows)
auto reserve(o2::framework::pack< ARGS... > &&, int s)
auto persist(std::array< char const *, sizeof...(ARGS)+1 > const &columnNames)
std::shared_ptr< arrow::Table > finalize()
auto preallocatedPersist(std::array< char const *, NCOLUMNS > const &columnNames, int nRows)
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint buffer
Definition glcorearb.h:655
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
FIXME: do not use data model tables.