Project
Loading...
Searching...
No Matches
benchmark_TableToTree.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
14#include <benchmark/benchmark.h>
15#include <random>
16#include <vector>
17
18#include <TFile.h>
19
20using namespace o2::framework;
21using namespace arrow;
22using namespace o2::soa;
23
24namespace test
25{
26DECLARE_SOA_COLUMN(X, x, float);
27DECLARE_SOA_COLUMN(Y, y, float);
28DECLARE_SOA_COLUMN(Z, z, float);
29DECLARE_SOA_DYNAMIC_COLUMN(Sum, sum, [](float x, float y) { return x + y; });
30} // namespace test
31
32#ifdef __APPLE__
33constexpr unsigned int maxrange = 15;
34#else
35constexpr unsigned int maxrange = 16;
36#endif
37
38static void BM_TableToTree(benchmark::State& state)
39{
40
41 // initialize a random generator
42 std::default_random_engine e1(1234567891);
43 std::uniform_real_distribution<double> rd(0, 1);
44 std::normal_distribution<float> rf(5., 2.);
45 std::discrete_distribution<ULong64_t> rl({10, 20, 30, 30, 5, 5});
46 std::discrete_distribution<int> ri({10, 20, 30, 30, 5, 5});
47
48 // create a table and fill the columns with random numbers
49 TableBuilder builder;
50 auto rowWriter =
51 builder.persist<double, float, ULong64_t, int>({"a", "b", "c", "d"});
52 for (auto i = 0; i < state.range(0); ++i) {
53 rowWriter(0, rd(e1), rf(e1), rl(e1), ri(e1));
54 }
55 auto table = builder.finalize();
56
57 // loop over elements of state
58 for (auto _ : state) {
59
60 // Open file and create tree
61 TFile fout("table2tree.root", "RECREATE");
62
63 // benchmark TableToTree
64 TableToTree ta2tr(table, &fout, "table2tree");
65 ta2tr.addAllBranches();
66 ta2tr.process();
67
68 // clean up
69 fout.Close();
70 }
71
72 state.SetBytesProcessed(state.iterations() * state.range(0) * 24);
73}
74
75BENCHMARK(BM_TableToTree)->Range(8, 8 << maxrange);
76
#define DECLARE_SOA_DYNAMIC_COLUMN(_Name_, _Getter_,...)
Definition ASoA.h:2967
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_)
Definition ASoA.h:2314
benchmark::State & state
int32_t i
BENCHMARK_MAIN()
constexpr unsigned int maxrange
BENCHMARK(BM_TableToTree) -> Range(8, 8<< maxrange)
auto persist(std::array< char const *, sizeof...(ARGS)+1 > const &columnNames)
std::shared_ptr< TTree > process()
float sum(float s, o2::dcs::DataPointValue v)
Definition dcs-ccdb.cxx:39
GLint GLenum GLint x
Definition glcorearb.h:403
GLint y
Definition glcorearb.h:270
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
FIXME: do not use data model tables.
std::random_device rd