Project
Loading...
Searching...
No Matches
BenchCathodeSegmentation.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
15#include <algorithm>
16#include <random>
17#include "benchmark/benchmark.h"
20
21struct TestPoint {
22 double x, y;
23};
24
25std::vector<TestPoint> generateUniformTestPoints(int n, double xmin, double ymin, double xmax, double ymax)
26{
27 std::random_device rd;
28 std::mt19937 mt(rd());
29 std::vector<TestPoint> testPoints;
30
31 testPoints.resize(n);
32 std::uniform_real_distribution<double> distX{xmin, xmax};
33 std::uniform_real_distribution<double> distY{ymin, ymax};
34 std::generate(testPoints.begin(), testPoints.end(), [&distX, &distY, &mt] {
35 return TestPoint{distX(mt), distY(mt)};
36 });
37
38 return testPoints;
39}
40
41static void segmentationList(benchmark::internal::Benchmark* b)
42{
44 for (auto bending : {true, false}) {
45 {
46 b->Args({detElemId, bending});
47 }
48 }
49 });
50}
51
52class BenchO2 : public benchmark::Fixture
53{
54};
55
56BENCHMARK_DEFINE_F(BenchO2, ctor)
57(benchmark::State& state)
58{
59 int detElemId = state.range(0);
60 bool isBendingPlane = state.range(1);
61
62 for (auto _ : state) {
64 }
65}
66
67std::vector<int> getDetElemIds()
68{
69 std::vector<int> deids;
71 [&deids](int detElemId) { deids.push_back(detElemId); });
72 return deids;
73}
74
75static void benchCathodeSegmentationConstructionAll(benchmark::State& state)
76{
77 std::vector<int> deids = getDetElemIds();
78 for (auto _ : state) {
79 for (auto detElemId : deids) {
80 for (auto bending : {true, false}) {
82 }
83 }
84 }
85}
86
87BENCHMARK_DEFINE_F(BenchO2, findPadByFEE)
88(benchmark::State& state)
89{
90 int detElemId = state.range(0);
91 bool isBendingPlane = state.range(1);
93
94 int ntp{0};
95 for (auto _ : state) {
96 ntp = 0;
97 int nds = seg.nofDualSampas();
98 for (int ds = 0; ds < nds; ++ds) {
99 auto dualSampaId = seg.dualSampaId(ds);
100 for (int ch = 0; ch < 64; ch++) {
101 seg.findPadByFEE(dualSampaId, ch);
102 }
103 ++ntp;
104 }
105 }
106 state.counters["ntp"] = ntp;
107}
108
109// note: a bench is not a test, so here we assume findPadByPosition is correct,
110// we just time it.
111// so you must have a test of it somewhere else.
112BENCHMARK_DEFINE_F(BenchO2, findPadByPosition)
113(benchmark::State& state)
114{
115 int detElemId = state.range(0);
116 bool isBendingPlane = state.range(1);
119
120 const int n = 100000;
121 auto testpoints = generateUniformTestPoints(n, bbox.xmin(), bbox.ymin(), bbox.xmax(), bbox.ymax());
122
123 int ntp{0};
124 for (auto _ : state) {
125 ntp = 0;
126 for (auto& tp : testpoints) {
127 seg.findPadByPosition(tp.x, tp.y);
128 ++ntp;
129 }
130 }
131 state.counters["ntp"] = ntp;
132}
133
134BENCHMARK(benchCathodeSegmentationConstructionAll)->Unit(benchmark::kMillisecond);
135
136BENCHMARK_REGISTER_F(BenchO2, findPadByPosition)->Apply(segmentationList)->Unit(benchmark::kMillisecond);
137BENCHMARK_REGISTER_F(BenchO2, findPadByFEE)->Apply(segmentationList)->Unit(benchmark::kMillisecond);
138
139BENCHMARK_REGISTER_F(BenchO2, ctor)->Apply(segmentationList)->Unit(benchmark::kMicrosecond);
140
bool isBendingPlane
BENCHMARK_MAIN()
std::vector< TestPoint > generateUniformTestPoints(int n, double xmin, double ymin, double xmax, double ymax)
BENCHMARK_REGISTER_F(BenchO2, findPadByPosition) -> Apply(segmentationList) ->Unit(benchmark::kMillisecond)
o2::mch::mapping::CathodeSegmentation seg
benchmark::State & state
BENCHMARK(benchCathodeSegmentationConstructionAll) -> Unit(benchmark::kMillisecond)
std::vector< int > getDetElemIds()
A CathodeSegmentation lets you find pads on a given plane (cathode) of a detection element and then i...
int dualSampaId(int dualSampaIndex) const
int findPadByPosition(double x, double y) const
int findPadByFEE(int dualSampaId, int dualSampaChannel) const
GLdouble n
Definition glcorearb.h:1982
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
int detElemId(Chamber chamber, Side side, int number)
void forOneDetectionElementOfEachSegmentationType(CALLABLE &&func)
o2::mch::contour::BBox< double > getBBox(const CathodeSegmentation &seg)
o2::mch::DsIndex ds
std::random_device rd