Project
Loading...
Searching...
No Matches
BenchSegmentation.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"
19
20static void segmentationList(benchmark::internal::Benchmark* b)
21{
23 b->Args({detElemId});
24 });
25}
26
27class BenchSegO2 : public benchmark::Fixture
28{
29};
30
31BENCHMARK_DEFINE_F(BenchSegO2, ctor)
32(benchmark::State& state)
33{
34 int detElemId = state.range(0);
35
36 for (auto _ : state) {
38 }
39}
40
41namespace
42{
43std::vector<int> getDetElemIds()
44{
45 std::vector<int> deids;
47 [&deids](int detElemId) { deids.push_back(detElemId); });
48 return deids;
49}
50} // namespace
51
52static void benchSegmentationCtorAll(benchmark::State& state)
53{
54 std::vector<int> deids = getDetElemIds();
55 for (auto _ : state) {
56 for (auto detElemId : deids) {
58 }
59 }
60}
61
62static void benchSegmentationCtorMap(benchmark::State& state)
63{
64 std::vector<int> deids = getDetElemIds();
65 std::map<int, o2::mch::mapping::Segmentation> cache;
66
67 for (auto _ : state) {
68 for (auto detElemId : deids) {
69 cache.emplace(detElemId, o2::mch::mapping::Segmentation(detElemId));
70 }
71 }
72}
73
74static void benchSegmentationCtorMapPtr(benchmark::State& state)
75{
76 std::vector<int> deids = getDetElemIds();
77 std::map<int, o2::mch::mapping::Segmentation*> cache;
78
79 for (auto _ : state) {
80 for (auto detElemId : deids) {
81 cache.emplace(detElemId, new o2::mch::mapping::Segmentation(detElemId));
82 }
83 }
84}
85BENCHMARK(benchSegmentationCtorAll)->Unit(benchmark::kMillisecond);
86BENCHMARK(benchSegmentationCtorMap)->Unit(benchmark::kMillisecond);
87BENCHMARK(benchSegmentationCtorMapPtr)->Unit(benchmark::kMillisecond);
88
89BENCHMARK_REGISTER_F(BenchSegO2, ctor)->Apply(segmentationList)->Unit(benchmark::kMicrosecond);
o2::mch::mapping::CathodeSegmentation seg
std::vector< int > getDetElemIds()
BENCHMARK_REGISTER_F(BenchSegO2, ctor) -> Apply(segmentationList) ->Unit(benchmark::kMicrosecond)
BENCHMARK(benchSegmentationCtorAll) -> Unit(benchmark::kMillisecond)
benchmark::State & state
A Segmentation lets you find pads of a detection element and then inspect those pads.
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
int detElemId(Chamber chamber, Side side, int number)
void forOneDetectionElementOfEachSegmentationType(CALLABLE &&func)
void forEachDetectionElement(CALLABLE &&func)