15#include <benchmark/benchmark.h>
44static void BM_SimpleForLoop(benchmark::State& state)
55 std::default_random_engine e1(1234567891);
56 std::uniform_real_distribution<float>
uniform_dist(0, 1);
58 for (
auto i = 0;
i <
state.range(0); ++
i) {
62 for (
auto _ :
state) {
65 benchmark::DoNotOptimize(
sum++);
68 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
73static void BM_TrackForLoop(benchmark::State& state)
83 std::vector<TestTrack>
foo;
87 std::default_random_engine e1(1234567891);
88 std::uniform_real_distribution<float>
uniform_dist(0, 1);
90 for (
auto i = 0;
i <
state.range(0); ++
i) {
96 for (
auto _ :
state) {
98 for (
auto& xyz :
foo) {
101 benchmark::DoNotOptimize(
sum);
103 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
108static void BM_WholeTrackForLoop(benchmark::State& state)
118 std::vector<TestTrack>
foo;
122 std::default_random_engine e1(1234567891);
123 std::uniform_real_distribution<float>
uniform_dist(0, 1);
125 for (
auto i = 0;
i <
state.range(0); ++
i) {
131 for (
auto _ :
state) {
133 for (
auto& xyz :
foo) {
134 sum += xyz.a + xyz.b + xyz.c + xyz.d + xyz.e + xyz.f;
136 benchmark::DoNotOptimize(
sum);
138 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 6);
143static void BM_TrackForPhi(benchmark::State& state)
153 std::vector<TestTrack>
foo;
157 std::default_random_engine e1(1234567891);
158 std::uniform_real_distribution<float>
uniform_dist(0, 1);
160 for (
auto i = 0;
i <
state.range(0); ++
i) {
166 for (
auto _ :
state) {
168 std::vector<float>
result;
170 for (
auto& track :
foo) {
171 result[
i++] = asin(track.a) + track.d + M_PI;
173 benchmark::DoNotOptimize(
result);
175 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
180static void BM_SimpleForLoopWithOp(benchmark::State& state)
187 std::vector<XYZ>
foo;
191 std::default_random_engine e1(1234567891);
192 std::uniform_real_distribution<float>
uniform_dist(0, 1);
194 for (
auto i = 0;
i <
state.range(0); ++
i) {
198 for (
auto _ :
state) {
200 for (
auto& xyz :
foo) {
201 sum += xyz.
x + xyz.y;
203 benchmark::DoNotOptimize(
sum);
205 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
210static void BM_ASoASimpleForLoop(benchmark::State& state)
213 std::default_random_engine e1(1234567891);
214 std::uniform_real_distribution<float>
uniform_dist(0, 1);
217 auto rowWriter = builder.
persist<float, float,
float>({
"x",
"y",
"z"});
218 for (
auto i = 0;
i <
state.range(0); ++
i) {
225 for (
auto _ :
state) {
228 for (
auto& _ : tests) {
231 benchmark::DoNotOptimize(
sum++);
233 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
238static void BM_ASoASimpleForLoopWithOp(benchmark::State& state)
241 std::default_random_engine e1(1234567891);
242 std::uniform_real_distribution<float>
uniform_dist(0, 1);
245 auto rowWriter = builder.
persist<float, float,
float>({
"x",
"y",
"z"});
246 for (
auto i = 0;
i <
state.range(0); ++
i) {
253 for (
auto _ :
state) {
256 for (
auto&
test : tests) {
259 benchmark::DoNotOptimize(
sum);
261 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
266static void BM_ASoADynamicColumnPresent(benchmark::State& state)
269 std::default_random_engine e1(1234567891);
270 std::uniform_real_distribution<float>
uniform_dist(0, 1);
273 auto rowWriter = builder.
persist<float, float,
float>({
"x",
"y",
"z"});
274 for (
auto i = 0;
i <
state.range(0); ++
i) {
281 for (
auto _ :
state) {
284 for (
auto&
test : tests) {
287 benchmark::DoNotOptimize(
sum);
289 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
294static void BM_ASoADynamicColumnPresentGetGetterByLabel(benchmark::State& state)
297 std::default_random_engine e1(1234567891);
298 std::uniform_real_distribution<float>
uniform_dist(0, 1);
301 auto rowWriter = builder.
persist<float, float,
float>({
"x",
"y",
"z"});
302 for (
auto i = 0;
i <
state.range(0); ++
i) {
309 for (
auto _ :
state) {
312 auto xGetter = o2::soa::row_helpers::getColumnGetterByLabel<float, Test>(
"x");
313 auto yGetter = o2::soa::row_helpers::getColumnGetterByLabel<float, Test>(
"y");
314 for (
auto&
test : tests) {
317 benchmark::DoNotOptimize(
sum);
319 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
324static void BM_ASoADynamicColumnCall(benchmark::State& state)
327 std::default_random_engine e1(1234567891);
328 std::uniform_real_distribution<float>
uniform_dist(0, 1);
331 auto rowWriter = builder.
persist<float, float,
float>({
"x",
"y",
"z"});
332 for (
auto i = 0;
i <
state.range(0); ++
i) {
340 for (
auto _ :
state) {
342 for (
auto&
test : tests) {
345 benchmark::DoNotOptimize(
sum);
347 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
351static void BM_ASoADynamicColumnCallGetGetterByLabel(benchmark::State& state)
354 std::default_random_engine e1(1234567891);
355 std::uniform_real_distribution<float>
uniform_dist(0, 1);
358 auto rowWriter = builder.
persist<float, float,
float>({
"x",
"y",
"z"});
359 for (
auto i = 0;
i <
state.range(0); ++
i) {
365 using Test =
o2::soa::InPlaceTable<
"A/0"_h, test::X, test::Y, test::Sum<test::X, test::Y>, test::SumFreeArgs<test::X, test::Y>>;
368 for (
auto _ :
state) {
370 auto sumGetter = o2::soa::row_helpers::getColumnGetterByLabel<float, Test>(
"Sum");
371 for (
auto&
test : tests) {
374 benchmark::DoNotOptimize(
sum);
376 state.SetBytesProcessed(
state.iterations() *
state.range(0) *
sizeof(
float) * 2);
#define DECLARE_SOA_DYNAMIC_COLUMN(_Name_, _Getter_,...)
#define DECLARE_SOA_TABLE(_Name_, _Origin_, _Desc_,...)
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
uniform_int_distribution< long long > uniform_dist(32, 126)
BENCHMARK(BM_SimpleForLoop) -> Range(8, 8<< maxrange)
constexpr unsigned int maxrange
auto persist(std::array< char const *, sizeof...(ARGS)+1 > const &columnNames)
std::shared_ptr< arrow::Table > finalize()
float sum(float s, o2::dcs::DataPointValue v)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
GLdouble GLdouble GLdouble z
Defining PrimaryVertex explicitly as messageable.
FIXME: do not use data model tables.