Project
Loading...
Searching...
No Matches
benchmark_ASoAHelpers.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
15#include <benchmark/benchmark.h>
16#include <random>
17#include <vector>
18
19using namespace o2::framework;
20using namespace arrow;
21using namespace o2::soa;
22
24
25namespace test
26{
27DECLARE_SOA_COLUMN_FULL(X, x, float, "x");
28DECLARE_SOA_COLUMN_FULL(Y, y, float, "y");
29DECLARE_SOA_COLUMN_FULL(Z, z, float, "z");
30DECLARE_SOA_DYNAMIC_COLUMN(Sum, sum, [](float x, float y) { return x + y; });
31} // namespace test
32
33#ifdef __APPLE__
34constexpr unsigned int maxPairsRange = 10;
35constexpr unsigned int maxFivesRange = 3;
36#else
37constexpr unsigned int maxPairsRange = 12;
38constexpr unsigned int maxFivesRange = 3;
39#endif
40
41static void BM_ASoAHelpersEmptySimplePairs(benchmark::State& state)
42{
43 int64_t count = 0;
44
45 for (auto _ : state) {
46 count = 0;
47 int n = state.range(0);
48 for (int i = 0; i < n - 1; i++) {
49 for (int j = i + 1; j < n; j++) {
50 count++;
51 }
52 }
53 benchmark::DoNotOptimize(count);
54 }
55 state.counters["Combinations"] = count;
56 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
57}
58
59BENCHMARK(BM_ASoAHelpersEmptySimplePairs)->Range(8, 8 << maxPairsRange);
60
61static void BM_ASoAHelpersEmptySimpleFives(benchmark::State& state)
62{
63 int64_t count = 0;
64
65 for (auto _ : state) {
66 count = 0;
67 int n = state.range(0);
68 for (int i = 0; i < n - 4; i++) {
69 for (int j = i + 1; j < n - 3; j++) {
70 for (int k = j + 1; k < n - 2; k++) {
71 for (int l = k + 1; l < n - 1; l++) {
72 for (int m = l + 1; m < n; m++) {
73 count++;
74 }
75 }
76 }
77 }
78 }
79 benchmark::DoNotOptimize(count);
80 }
81 state.counters["Combinations"] = count;
82 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
83}
84
85BENCHMARK(BM_ASoAHelpersEmptySimpleFives)->RangeMultiplier(2)->Range(8, 8 << maxFivesRange);
86
87static void BM_ASoAHelpersNaiveSimplePairs(benchmark::State& state)
88{
89 // Seed with a real random value, if available
90 std::default_random_engine e1(1234567891);
91 std::uniform_real_distribution<float> uniform_dist(0, 1);
92
93 TableBuilder builder;
94 auto rowWriter = builder.persist<float, float, float>({"x", "y", "z"});
95 for (auto i = 0; i < state.range(0); ++i) {
96 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1));
97 }
98 auto table = builder.finalize();
99
100 using Test = o2::soa::InPlaceTable<"A/1"_h, test::X>;
101 Test tests{table};
102 int64_t count = 0;
103
104 for (auto _ : state) {
105 count = 0;
106 for (auto t0 = tests.begin(); t0 + 1 != tests.end(); ++t0) {
107 for (auto t1 = t0 + 1; t1 != tests.end(); ++t1) {
108 auto comb = std::make_tuple(t0, t1);
109 count++;
110 benchmark::DoNotOptimize(comb);
111 }
112 }
113 benchmark::DoNotOptimize(count);
114 }
115 state.counters["Combinations"] = count;
116 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
117}
118
119BENCHMARK(BM_ASoAHelpersNaiveSimplePairs)->Range(8, 8 << maxPairsRange);
120
121static void BM_ASoAHelpersNaiveSimpleFives(benchmark::State& state)
122{
123 // Seed with a real random value, if available
124 std::default_random_engine e1(1234567891);
125 std::uniform_real_distribution<float> uniform_dist(0, 1);
126
127 TableBuilder builder;
128 auto rowWriter = builder.persist<float, float, float>({"x", "y", "z"});
129 for (auto i = 0; i < state.range(0); ++i) {
130 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1));
131 }
132 auto table = builder.finalize();
133
134 using Test = o2::soa::InPlaceTable<"A/2"_h, test::X>;
135 Test tests{table};
136 int64_t count = 0;
137
138 for (auto _ : state) {
139 count = 0;
140 for (auto t0 = tests.begin(); t0 + 4 != tests.end(); ++t0) {
141 for (auto t1 = t0 + 1; t1 + 3 != tests.end(); ++t1) {
142 for (auto t2 = t1 + 1; t2 + 2 != tests.end(); ++t2) {
143 for (auto t3 = t2 + 1; t3 + 1 != tests.end(); ++t3) {
144 for (auto t4 = t3 + 1; t4 != tests.end(); ++t4) {
145 auto comb = std::make_tuple(t0, t1, t2, t3, t4);
146 count++;
147 benchmark::DoNotOptimize(comb);
148 }
149 }
150 }
151 }
152 }
153 benchmark::DoNotOptimize(count);
154 }
155 state.counters["Combinations"] = count;
156 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
157}
158
159BENCHMARK(BM_ASoAHelpersNaiveSimpleFives)->RangeMultiplier(2)->Range(8, 8 << maxFivesRange);
160
161static void BM_ASoAHelpersNaiveCalosPairs(benchmark::State& state)
162{
163 // Seed with a real random value, if available
164 std::default_random_engine e1(1234567891);
165 std::uniform_real_distribution<float> uniform_dist(0, 1);
166
167 TableBuilder builder;
168 auto rowWriter = builder.cursor<o2::aod::Calos>();
169 for (auto i = 0; i < state.range(0); ++i) {
170 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1),
172 }
173 auto table = builder.finalize();
174
175 o2::aod::Calos Calos{table};
176 int64_t count = 0;
177
178 for (auto _ : state) {
179 count = 0;
180 for (auto t0 = Calos.begin(); t0 + 1 != Calos.end(); ++t0) {
181 for (auto t1 = t0 + 1; t1 != Calos.end(); ++t1) {
182 auto comb = std::make_tuple(t0, t1);
183 count++;
184 benchmark::DoNotOptimize(comb);
185 }
186 }
187 benchmark::DoNotOptimize(count);
188 }
189 state.counters["Combinations"] = count;
190 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
191}
192
193BENCHMARK(BM_ASoAHelpersNaiveCalosPairs)->Range(8, 8 << (maxPairsRange - 3));
194
195static void BM_ASoAHelpersNaiveCalosFives(benchmark::State& state)
196{
197 // Seed with a real random value, if available
198 std::default_random_engine e1(1234567891);
199 std::uniform_real_distribution<float> uniform_dist(0, 1);
200
201 TableBuilder builder;
202 auto rowWriter = builder.cursor<o2::aod::Calos>();
203 for (auto i = 0; i < state.range(0); ++i) {
204 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1),
206 }
207 auto table = builder.finalize();
208
209 o2::aod::Calos calos{table};
210 int64_t count = 0;
211
212 for (auto _ : state) {
213 count = 0;
214 for (auto t0 = calos.begin(); t0 + 4 != calos.end(); ++t0) {
215 for (auto t1 = t0 + 1; t1 + 3 != calos.end(); ++t1) {
216 for (auto t2 = t1 + 1; t2 + 2 != calos.end(); ++t2) {
217 for (auto t3 = t2 + 1; t3 + 1 != calos.end(); ++t3) {
218 for (auto t4 = t3 + 1; t4 != calos.end(); ++t4) {
219 auto comb = std::make_tuple(t0, t1, t2, t3, t4);
220 count++;
221 benchmark::DoNotOptimize(comb);
222 }
223 }
224 }
225 }
226 }
227 benchmark::DoNotOptimize(count);
228 }
229 state.counters["Combinations"] = count;
230 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
231}
232
233BENCHMARK(BM_ASoAHelpersNaiveCalosFives)->RangeMultiplier(2)->Range(8, 8 << maxFivesRange);
234
235static void BM_ASoAHelpersNaiveTracksPairs(benchmark::State& state)
236{
237 // Seed with a real random value, if available
238 std::default_random_engine e1(1234567891);
239 std::uniform_real_distribution<float> uniform_dist(0, 1);
240 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
241
242 TableBuilder builder;
243 auto rowWriter = builder.cursor<o2::aod::StoredTracks>();
244 for (auto i = 0; i < state.range(0); ++i) {
245 rowWriter(0, uniform_dist_int(e1), 0,
248 }
249 auto table = builder.finalize();
250
251 o2::aod::StoredTracks tracks{table};
252 int64_t count = 0;
253
254 for (auto _ : state) {
255 count = 0;
256 for (auto t0 = tracks.begin(); t0 + 1 != tracks.end(); ++t0) {
257 for (auto t1 = t0 + 1; t1 != tracks.end(); ++t1) {
258 auto comb = std::make_tuple(t0, t1);
259 count++;
260 benchmark::DoNotOptimize(comb);
261 }
262 }
263 benchmark::DoNotOptimize(count);
264 }
265 state.counters["Combinations"] = count;
266 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
267}
268
269BENCHMARK(BM_ASoAHelpersNaiveTracksPairs)->Range(8, 8 << (maxPairsRange - 3));
270
271static void BM_ASoAHelpersNaiveTracksFives(benchmark::State& state)
272{
273 // Seed with a real random value, if available
274 std::default_random_engine e1(1234567891);
275 std::uniform_real_distribution<float> uniform_dist(0, 1);
276 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
277
278 TableBuilder builder;
279 auto rowWriter = builder.cursor<o2::aod::StoredTracks>();
280 for (auto i = 0; i < state.range(0); ++i) {
281 rowWriter(0, uniform_dist_int(e1), 0,
284 }
285 auto table = builder.finalize();
286
287 o2::aod::StoredTracks tracks{table};
288 int64_t count = 0;
289
290 for (auto _ : state) {
291 count = 0;
292 for (auto t0 = tracks.begin(); t0 + 4 != tracks.end(); ++t0) {
293 for (auto t1 = t0 + 1; t1 + 3 != tracks.end(); ++t1) {
294 for (auto t2 = t1 + 1; t2 + 2 != tracks.end(); ++t2) {
295 for (auto t3 = t2 + 1; t3 + 1 != tracks.end(); ++t3) {
296 for (auto t4 = t3 + 1; t4 != tracks.end(); ++t4) {
297 auto comb = std::make_tuple(t0, t1, t2, t3, t4);
298 count++;
299 benchmark::DoNotOptimize(comb);
300 }
301 }
302 }
303 }
304 }
305 benchmark::DoNotOptimize(count);
306 }
307 state.counters["Combinations"] = count;
308 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
309}
310
311BENCHMARK(BM_ASoAHelpersNaiveTracksFives)->RangeMultiplier(2)->Range(8, 8 << maxFivesRange);
312
313static void BM_ASoAHelpersCombGenSimplePairs(benchmark::State& state)
314{
315 // Seed with a real random value, if available
316 std::default_random_engine e1(1234567891);
317 std::uniform_real_distribution<float> uniform_dist(0, 1);
318
319 TableBuilder builder;
320 auto rowWriter = builder.persist<float, float, float>({"x", "y", "z"});
321 for (auto i = 0; i < state.range(0); ++i) {
322 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1));
323 }
324 auto table = builder.finalize();
325
326 using Test = o2::soa::InPlaceTable<"A/0"_h, test::X>;
327 Test tests{table};
328
329 int64_t count = 0;
330
331 for (auto _ : state) {
332 count = 0;
333 for (auto& comb : combinations(tests, tests)) {
334 count++;
335 }
336 benchmark::DoNotOptimize(count);
337 }
338 state.counters["Combinations"] = count;
339 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
340}
341
342BENCHMARK(BM_ASoAHelpersCombGenSimplePairs)->Range(8, 8 << maxPairsRange);
343
344static void BM_ASoAHelpersCombGenSimpleFives(benchmark::State& state)
345{
346 // Seed with a real random value, if available
347 std::default_random_engine e1(1234567891);
348 std::uniform_real_distribution<float> uniform_dist(0, 1);
349
350 TableBuilder builder;
351 auto rowWriter = builder.persist<float, float, float>({"x", "y", "z"});
352 for (auto i = 0; i < state.range(0); ++i) {
353 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1));
354 }
355 auto table = builder.finalize();
356
357 using Test = o2::soa::InPlaceTable<"A/0"_h, test::X>;
358 Test tests{table};
359
360 int64_t count = 0;
361
362 for (auto _ : state) {
363 count = 0;
364 for (auto& comb : combinations(tests, tests, tests, tests, tests)) {
365 count++;
366 }
367 benchmark::DoNotOptimize(count);
368 }
369 state.counters["Combinations"] = count;
370 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
371}
372
373BENCHMARK(BM_ASoAHelpersCombGenSimpleFives)->RangeMultiplier(2)->Range(8, 8 << maxFivesRange);
374
375static void BM_ASoAHelpersCombGenCalosPairs(benchmark::State& state)
376{
377 // Seed with a real random value, if available
378 std::default_random_engine e1(1234567891);
379 std::uniform_real_distribution<float> uniform_dist(0, 1);
380
381 TableBuilder builder;
382 auto rowWriter = builder.cursor<o2::aod::Calos>();
383 for (auto i = 0; i < state.range(0); ++i) {
384 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1),
386 }
387 auto table = builder.finalize();
388
389 o2::aod::Calos calos{table};
390
391 int64_t count = 0;
392
393 for (auto _ : state) {
394 count = 0;
395 for (auto& comb : combinations(calos, calos)) {
396 count++;
397 }
398 benchmark::DoNotOptimize(count);
399 }
400 state.counters["Combinations"] = count;
401 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
402}
403
404BENCHMARK(BM_ASoAHelpersCombGenCalosPairs)->Range(8, 8 << (maxPairsRange - 3));
405
406static void BM_ASoAHelpersCombGenCalosFives(benchmark::State& state)
407{
408 // Seed with a real random value, if available
409 std::default_random_engine e1(1234567891);
410 std::uniform_real_distribution<float> uniform_dist(0, 1);
411
412 TableBuilder builder;
413 auto rowWriter = builder.cursor<o2::aod::Calos>();
414 for (auto i = 0; i < state.range(0); ++i) {
415 rowWriter(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1),
417 }
418 auto table = builder.finalize();
419
420 o2::aod::Calos calos{table};
421
422 int64_t count = 0;
423
424 for (auto _ : state) {
425 count = 0;
426 for (auto& comb : combinations(calos, calos, calos, calos, calos)) {
427 count++;
428 }
429 benchmark::DoNotOptimize(count);
430 }
431 state.counters["Combinations"] = count;
432 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
433}
434
435BENCHMARK(BM_ASoAHelpersCombGenCalosFives)->RangeMultiplier(2)->Range(8, 8 << maxFivesRange);
436
437static void BM_ASoAHelpersCombGenTracksPairs(benchmark::State& state)
438{
439 // Seed with a real random value, if available
440 std::default_random_engine e1(1234567891);
441 std::uniform_real_distribution<float> uniform_dist(0, 1);
442 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
443
444 TableBuilder builder;
445 auto rowWriter = builder.cursor<o2::aod::StoredTracks>();
446 for (auto i = 0; i < state.range(0); ++i) {
447 rowWriter(0, uniform_dist_int(e1), 0,
450 }
451 auto table = builder.finalize();
452
453 o2::aod::StoredTracks tracks{table};
454
455 int64_t count = 0;
456
457 for (auto _ : state) {
458 count = 0;
459 for (auto& comb : combinations(tracks, tracks)) {
460 count++;
461 }
462 benchmark::DoNotOptimize(count);
463 }
464 state.counters["Combinations"] = count;
465 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
466}
467
468BENCHMARK(BM_ASoAHelpersCombGenTracksPairs)->Range(8, 8 << (maxPairsRange - 3));
469
470static void BM_ASoAHelpersCombGenTracksFives(benchmark::State& state)
471{
472 // Seed with a real random value, if available
473 std::default_random_engine e1(1234567891);
474 std::uniform_real_distribution<float> uniform_dist(0, 1);
475 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
476
477 TableBuilder builder;
478 auto rowWriter = builder.cursor<o2::aod::StoredTracks>();
479 for (auto i = 0; i < state.range(0); ++i) {
480 rowWriter(0, uniform_dist_int(e1), 0,
483 }
484 auto table = builder.finalize();
485
486 o2::aod::StoredTracks tracks{table};
487
488 int64_t count = 0;
489
490 for (auto _ : state) {
491 count = 0;
492 for (auto& comb : combinations(tracks, tracks, tracks, tracks, tracks)) {
493 count++;
494 }
495 benchmark::DoNotOptimize(count);
496 }
497 state.counters["Combinations"] = count;
498 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
499}
500
501BENCHMARK(BM_ASoAHelpersCombGenTracksFives)->RangeMultiplier(2)->Range(8, 8 << maxFivesRange);
502
503static void BM_ASoAHelpersCombGenSimpleFivesMultipleChunks(benchmark::State& state)
504{
505 // Seed with a real random value, if available
506 std::default_random_engine e1(1234567891);
507 std::uniform_real_distribution<float> uniform_dist(0, 1);
508
509 TableBuilder builderA;
510 auto rowWriterA = builderA.persist<float, float, float>({"x", "y", "z"});
511 for (auto i = 0; i < state.range(0); ++i) {
512 rowWriterA(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1));
513 }
514 auto tableA = builderA.finalize();
515
516 TableBuilder builderB;
517 auto rowWriterB = builderB.persist<int32_t>({"x"});
518 for (auto i = 0; i < state.range(0); ++i) {
519 rowWriterB(0, uniform_dist(e1));
520 }
521 auto tableB = builderB.finalize();
522
523 using TestA = o2::soa::InPlaceTable<"A/0"_h, o2::soa::Index<>, test::X, test::Y>;
524 using TestB = o2::soa::InPlaceTable<"A/0"_h, o2::soa::Index<>, test::X>;
525 using ConcatTest = Concat<TestA, TestB>;
526
527 ConcatTest tests{tableA, tableB};
528
529 int64_t count = 0;
530
531 for (auto _ : state) {
532 count = 0;
533 for (auto& comb : combinations(tests, tests, tests, tests, tests)) {
534 count++;
535 }
536 benchmark::DoNotOptimize(count);
537 }
538 state.counters["Combinations"] = count;
539 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
540}
541
542BENCHMARK(BM_ASoAHelpersCombGenSimpleFivesMultipleChunks)->RangeMultiplier(2)->Range(8, 8 << (maxFivesRange - 1));
543
544static void BM_ASoAHelpersCombGenCalosFivesMultipleChunks(benchmark::State& state)
545{
546 // Seed with a real random value, if available
547 std::default_random_engine e1(1234567891);
548 std::uniform_real_distribution<float> uniform_dist(0, 1);
549
550 TableBuilder builderA;
551 auto rowWriterA = builderA.cursor<o2::aod::Calos>();
552 for (auto i = 0; i < state.range(0); ++i) {
553 rowWriterA(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1),
555 }
556 auto tableA = builderA.finalize();
557
558 TableBuilder builderB;
559 auto rowWriterB = builderB.cursor<o2::aod::Calos>();
560 for (auto i = 0; i < state.range(0); ++i) {
561 rowWriterB(0, uniform_dist(e1), uniform_dist(e1), uniform_dist(e1),
563 }
564 auto tableB = builderB.finalize();
565
567
568 ConcatTest calos{tableA, tableB};
569
570 int64_t count = 0;
571
572 for (auto _ : state) {
573 count = 0;
574 for (auto& comb : combinations(calos, calos, calos, calos, calos)) {
575 count++;
576 }
577 benchmark::DoNotOptimize(count);
578 }
579 state.counters["Combinations"] = count;
580 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
581}
582
583BENCHMARK(BM_ASoAHelpersCombGenCalosFivesMultipleChunks)->RangeMultiplier(2)->Range(8, 8 << (maxFivesRange - 1));
584
585static void BM_ASoAHelpersCombGenSimplePairsSameCategories(benchmark::State& state)
586{
587 // Seed with a real random value, if available
588 std::default_random_engine e1(1234567891);
589 std::uniform_real_distribution<float> uniform_dist(0, 1);
590 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
591
592 TableBuilder builder;
593 auto rowWriter = builder.persist<int, float, float>({"x", "y", "z"});
594 for (auto i = 0; i < state.range(0); ++i) {
595 rowWriter(0, uniform_dist_int(e1), uniform_dist(e1), uniform_dist(e1));
596 }
597 auto table = builder.finalize();
598
599 using Test = o2::soa::InPlaceTable<"A/0"_h, test::X>;
600 Test tests{table};
601 NoBinningPolicy<test::X> noBinning;
602
603 int64_t count = 0;
604
605 for (auto _ : state) {
606 count = 0;
607 for (auto& comb : combinations(CombinationsBlockUpperSameIndexPolicy(noBinning, 2, -1, tests, tests))) {
608 count++;
609 }
610 benchmark::DoNotOptimize(count);
611 }
612 state.counters["Combinations"] = count;
613 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
614}
615
616BENCHMARK(BM_ASoAHelpersCombGenSimplePairsSameCategories)->Range(8, 8 << maxPairsRange);
617
618static void BM_ASoAHelpersCombGenSimpleFivesSameCategories(benchmark::State& state)
619{
620 // Seed with a real random value, if available
621 std::default_random_engine e1(1234567891);
622 std::uniform_real_distribution<float> uniform_dist(0, 1);
623 std::uniform_int_distribution<int> uniform_dist_int(0, 5);
624
625 TableBuilder builder;
626 auto rowWriter = builder.persist<int, float, float>({"x", "y", "z"});
627 for (auto i = 0; i < state.range(0); ++i) {
628 rowWriter(0, uniform_dist_int(e1), uniform_dist(e1), uniform_dist(e1));
629 }
630 auto table = builder.finalize();
631
632 using Test = o2::soa::InPlaceTable<"A/0"_h, test::X>;
633 Test tests{table};
634 NoBinningPolicy<test::X> noBinning;
635
636 int64_t count = 0;
637
638 for (auto _ : state) {
639 count = 0;
640 for (auto& comb : combinations(CombinationsBlockUpperSameIndexPolicy(noBinning, 5, -1, tests, tests, tests, tests, tests))) {
641 count++;
642 }
643 benchmark::DoNotOptimize(count);
644 }
645 state.counters["Combinations"] = count;
646 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
647}
648
649BENCHMARK(BM_ASoAHelpersCombGenSimpleFivesSameCategories)->RangeMultiplier(2)->Range(8, 8 << (maxFivesRange + 1));
650
651static void BM_ASoAHelpersCombGenSimplePairsCategories(benchmark::State& state)
652{
653 // Seed with a real random value, if available
654 std::default_random_engine e1(1234567891);
655 std::uniform_real_distribution<float> uniform_dist(0, 1);
656 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
657
658 TableBuilder builder;
659 auto rowWriter = builder.persist<int, float, float>({"x", "y", "z"});
660 for (auto i = 0; i < state.range(0); ++i) {
661 rowWriter(0, uniform_dist_int(e1), uniform_dist(e1), uniform_dist(e1));
662 }
663 auto table = builder.finalize();
664
665 using Test = o2::soa::InPlaceTable<"A/0"_h, test::X>;
666 Test tests{table};
667 NoBinningPolicy<test::X> noBinning;
668
669 int64_t count = 0;
670
671 for (auto _ : state) {
672 count = 0;
673 for (auto& comb : combinations(CombinationsBlockUpperIndexPolicy(noBinning, 2, -1, tests, tests))) {
674 count++;
675 }
676 benchmark::DoNotOptimize(count);
677 }
678 state.counters["Combinations"] = count;
679 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
680}
681
682BENCHMARK(BM_ASoAHelpersCombGenSimplePairsCategories)->Range(8, 8 << maxPairsRange);
683
684static void BM_ASoAHelpersCombGenSimpleFivesCategories(benchmark::State& state)
685{
686 // Seed with a real random value, if available
687 std::default_random_engine e1(1234567891);
688 std::uniform_real_distribution<float> uniform_dist(0, 1);
689 std::uniform_int_distribution<int> uniform_dist_int(0, 5);
690
691 TableBuilder builder;
692 auto rowWriter = builder.persist<int, float, float>({"x", "y", "z"});
693 for (auto i = 0; i < state.range(0); ++i) {
694 rowWriter(0, uniform_dist_int(e1), uniform_dist(e1), uniform_dist(e1));
695 }
696 auto table = builder.finalize();
697
698 using Test = o2::soa::InPlaceTable<"A/0"_h, test::X>;
699 Test tests{table};
700 NoBinningPolicy<test::X> noBinning;
701
702 int64_t count = 0;
703
704 for (auto _ : state) {
705 count = 0;
706 for (auto& comb : combinations(CombinationsBlockUpperIndexPolicy(noBinning, 2, -1, tests, tests, tests, tests, tests))) {
707 count++;
708 }
709 benchmark::DoNotOptimize(count);
710 }
711 state.counters["Combinations"] = count;
712 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
713}
714
715BENCHMARK(BM_ASoAHelpersCombGenSimpleFivesCategories)->RangeMultiplier(2)->Range(8, 8 << (maxFivesRange + 1));
716
717static void BM_ASoAHelpersCombGenCollisionsPairsSameCategories(benchmark::State& state)
718{
719 // Seed with a real random value, if available
720 std::default_random_engine e1(1234567891);
721 std::uniform_real_distribution<float> uniform_dist(0, 1);
722 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
723
724 TableBuilder builder;
725 auto rowWriter = builder.cursor<o2::aod::Collisions>();
726 for (auto i = 0; i < state.range(0); ++i) {
727 rowWriter(0, uniform_dist_int(e1),
731 uniform_dist_int(e1), uniform_dist(e1),
732 uniform_dist_int(e1),
733 uniform_dist(e1), uniform_dist(e1));
734 }
735 auto table = builder.finalize();
736
737 o2::aod::Collisions collisions{table};
739
740 int64_t count = 0;
741
742 for (auto _ : state) {
743 count = 0;
744 for (auto& comb : combinations(CombinationsBlockUpperSameIndexPolicy(noBinning, 2, -1, collisions, collisions))) {
745 count++;
746 }
747 benchmark::DoNotOptimize(count);
748 }
749 state.counters["Combinations"] = count;
750 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
751}
752
753BENCHMARK(BM_ASoAHelpersCombGenCollisionsPairsSameCategories)->Range(8, 8 << maxPairsRange);
754
755static void BM_ASoAHelpersCombGenCollisionsFivesSameCategories(benchmark::State& state)
756{
757 // Seed with a real random value, if available
758 std::default_random_engine e1(1234567891);
759 std::uniform_real_distribution<float> uniform_dist(0, 1);
760 std::uniform_int_distribution<int> uniform_dist_int(0, 5);
761
762 TableBuilder builder;
763 auto rowWriter = builder.cursor<o2::aod::Collisions>();
764 for (auto i = 0; i < state.range(0); ++i) {
765 rowWriter(0, uniform_dist_int(e1),
769 uniform_dist_int(e1), uniform_dist(e1),
770 uniform_dist_int(e1),
771 uniform_dist(e1), uniform_dist(e1));
772 }
773 auto table = builder.finalize();
774
775 o2::aod::Collisions collisions{table};
777
778 int64_t count = 0;
779
780 for (auto _ : state) {
781 count = 0;
782 for (auto& comb : combinations(CombinationsBlockUpperSameIndexPolicy(noBinning, 5, -1, collisions, collisions, collisions, collisions, collisions))) {
783 count++;
784 }
785 benchmark::DoNotOptimize(count);
786 }
787 state.counters["Combinations"] = count;
788 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
789}
790
791BENCHMARK(BM_ASoAHelpersCombGenCollisionsFivesSameCategories)->RangeMultiplier(2)->Range(8, 8 << (maxFivesRange + 1));
792
793static void BM_ASoAHelpersCombGenCollisionsPairsCategories(benchmark::State& state)
794{
795 // Seed with a real random value, if available
796 std::default_random_engine e1(1234567891);
797 std::uniform_real_distribution<float> uniform_dist(0, 1);
798 std::uniform_int_distribution<int> uniform_dist_int(0, 10);
799
800 TableBuilder builder;
801 auto rowWriter = builder.cursor<o2::aod::Collisions>();
802 for (auto i = 0; i < state.range(0); ++i) {
803 rowWriter(0, uniform_dist_int(e1),
807 uniform_dist_int(e1), uniform_dist(e1),
808 uniform_dist_int(e1),
809 uniform_dist(e1), uniform_dist(e1));
810 }
811 auto table = builder.finalize();
812
813 o2::aod::Collisions collisions{table};
815
816 int64_t count = 0;
817
818 for (auto _ : state) {
819 count = 0;
820 for (auto& comb : combinations(CombinationsBlockUpperIndexPolicy(noBinning, 2, -1, collisions, collisions))) {
821 count++;
822 }
823 benchmark::DoNotOptimize(count);
824 }
825 state.counters["Combinations"] = count;
826 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
827}
828
829BENCHMARK(BM_ASoAHelpersCombGenCollisionsPairsCategories)->Range(8, 8 << maxPairsRange);
830
831static void BM_ASoAHelpersCombGenCollisionsFivesCategories(benchmark::State& state)
832{
833 // Seed with a real random value, if available
834 std::default_random_engine e1(1234567891);
835 std::uniform_real_distribution<float> uniform_dist(0, 1);
836 std::uniform_int_distribution<int> uniform_dist_int(0, 5);
837
838 TableBuilder builder;
839 auto rowWriter = builder.cursor<o2::aod::Collisions>();
840 for (auto i = 0; i < state.range(0); ++i) {
841 rowWriter(0, uniform_dist_int(e1),
845 uniform_dist_int(e1), uniform_dist(e1),
846 uniform_dist_int(e1),
847 uniform_dist(e1), uniform_dist(e1));
848 }
849 auto table = builder.finalize();
850
851 o2::aod::Collisions collisions{table};
853
854 int64_t count = 0;
855
856 for (auto _ : state) {
857 count = 0;
858 for (auto& comb : combinations(CombinationsBlockUpperIndexPolicy(noBinning, 5, -1, collisions, collisions, collisions, collisions, collisions))) {
859 count++;
860 }
861 benchmark::DoNotOptimize(count);
862 }
863 state.counters["Combinations"] = count;
864 state.SetBytesProcessed(state.iterations() * sizeof(float) * count);
865}
866
867BENCHMARK(BM_ASoAHelpersCombGenCollisionsFivesCategories)->RangeMultiplier(2)->Range(8, 8 << (maxFivesRange + 1));
868
#define DECLARE_SOA_DYNAMIC_COLUMN(_Name_, _Getter_,...)
Definition ASoA.h:2967
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
Definition ASoA.h:2285
benchmark::State & state
uniform_int_distribution< long long > uniform_dist(32, 126)
int32_t i
Test
Definition Utils.h:55
uint32_t j
Definition RawData.h:0
constexpr unsigned int maxPairsRange
BENCHMARK_MAIN()
BENCHMARK(BM_ASoAHelpersEmptySimplePairs) -> Range(8, 8<< maxPairsRange)
constexpr unsigned int maxFivesRange
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)
Definition dcs-ccdb.cxx:39
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLint GLsizei count
Definition glcorearb.h:399
GLint y
Definition glcorearb.h:270
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition glcorearb.h:5034
Collisions_001 Collisions
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
auto combinations(const BP &binningPolicy, int categoryNeighbours, const T1 &outsider, const T2s &... tables)
FIXME: do not use data model tables.