Project
Loading...
Searching...
No Matches
benchDigitMerging.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
12#include "benchmark/benchmark.h"
14#include "DigitMerging.h"
15#include <ctime>
16#include <cstdlib>
17
18using o2::mch::Digit;
19
20// createDigits generates N digits with random id
21// (hence some might get duplicated).
22std::vector<Digit> createDigits(int N)
23{
24 std::vector<Digit> digits;
25 float dummyadc{42.0};
26 std::srand(std::time(nullptr)); // use current time as seed for random generator
27 int dummydetID = 100; //to be improved, timing depending on that
28
29 for (auto i = 0; i < N; i++) {
30 int randomPadID = std::rand() * N;
31 digits.emplace_back(dummydetID, randomPadID, dummyadc, 0);
32 }
33
34 return digits;
35}
36
37std::vector<o2::MCCompLabel> createLabels(int N)
38{
39 std::vector<o2::MCCompLabel> labels;
40 int dummyEventID{1000};
41 std::srand(std::time(nullptr)); // use current time as seed for random generator
42 float dummysrcID{10};
43
44 for (auto i = 0; i < N; i++) {
45 int randomTrackID = std::rand() * N;
46 labels.emplace_back(randomTrackID, dummyEventID, dummysrcID, false);
47 }
48
49 return labels;
50}
51
52// benchDigitMerging create fake digits and merges them
53// using one of the merging functions.
54static void benchDigitMerging(benchmark::State& state)
55{
56 auto digits = createDigits(100);
57 auto labels = createLabels(100);
58
59 auto mergingFunction = mergingFunctions()[state.range(0)];
60
61 for (auto _ : state) {
62 mergingFunction(digits, labels);
63 }
64}
65
66// mergingFunctionIndices generate arguments from 0 to # merging functions - 1
67// to be used in the BENCHMARK macro below.
68static void mergingFunctionIndices(benchmark::internal::Benchmark* b)
69{
70 for (auto i = 0; i < mergingFunctions().size(); i++) {
71 b->Args({i});
72 }
73}
74
75// This effectively register as many benchmarks as there are functions
76// in the mergingFunctions vector.
77BENCHMARK(benchDigitMerging)->Apply(mergingFunctionIndices);
78
benchmark::State & state
std::vector< MergingFunctionType > mergingFunctions()
int32_t i
BENCHMARK_MAIN()
BENCHMARK(benchDigitMerging) -> Apply(mergingFunctionIndices)
std::vector< Digit > createDigits(int N)
std::vector< o2::MCCompLabel > createLabels(int N)
MCH digit implementation.
Definition Digit.h:31
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
std::vector< Digit > digits