ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tools
PmbCxxUtils
doc
custombenchmark_example.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
PmbCxxUtils/CustomBenchmark.h
"
6
#include <algorithm>
7
#include <iostream>
8
#include <cstdlib>
9
#include <cmath>
10
11
//Example: Assume that we are bench-marking some simulation code, and
12
//we would like to know time spent as a function of pdg (just the
13
//absolute pdg value, and any |pdg|>99 we wrap to 99).
14
15
int
main
(
int
,
char
**)
16
{
17
srand(0);
18
const
unsigned
maxpdgrecord=99;
19
PMonUtils::CustomBenchmark
bench(maxpdgrecord+1);
//Create bench object, allowing to track 100 unique ids (0..99).
20
21
double
dummy(17.0);
22
for
(
unsigned
i=0;i<100;++i) {
23
int
pdg = -150+(rand()%30)*10;
24
int
id
= std::min<unsigned>(maxpdgrecord,abs(pdg));
//map pdg to a number in 0..99
25
bench.
begin
(
id
);
26
//Fake work begin
27
for
(
unsigned
j=0;j<3000*(abs(pdg)+1);++j)
28
dummy = sin(dummy);
29
//Fake work end
30
bench.
end
();
31
}
32
33
//Exactly the same loop once again, to show how to use the Guard mini helper:
34
for
(
unsigned
i=0;i<100;++i) {
35
int
pdg = -150+(rand()%30)*10;
36
int
id
= std::min<unsigned>(maxpdgrecord,abs(pdg));
//map pdg to a number in 0..99
37
{
38
PMonUtils::CustomBenchmarkGuard
cbg(&bench,
id
);
39
//Fake work begin
40
for
(
unsigned
j=0;j<3000*(abs(pdg)+1);++j)
41
dummy = sin(dummy);
//Even if an exception is thrown here, the destructor of the cbg object will invoke bench.end() for us.
42
//Fake work end
43
}
44
}
45
46
//Print out the results:
47
48
for
(
unsigned
pdg = 0; pdg<=maxpdgrecord; ++pdg) {
49
uint64_t
count
;
double
time_ms;
50
bench.
getData
(pdg,
count
, time_ms);
51
if
(
count
)
//Only report on those encountered at least once
52
std::cout<<
"Work done on particle with |pdg|="
<<pdg<<(pdg==maxpdgrecord?
"+"
:
""
)
53
<<
" was done "
<<
count
<<
" times and took a total of "
<<time_ms
54
<<
" milliseconds [on average "
<<time_ms/
count
<<
" ms each time]"
<<std::endl;
55
}
56
}
CustomBenchmark.h
PMonUtils::CustomBenchmarkGuard
Definition
CustomBenchmark.h:118
PMonUtils::CustomBenchmark
Definition
CustomBenchmark.h:30
PMonUtils::CustomBenchmark::end
void end(int count)
Definition
CustomBenchmark.h:73
PMonUtils::CustomBenchmark::begin
void begin(unsigned id)
Definition
CustomBenchmark.h:67
PMonUtils::CustomBenchmark::getData
void getData(unsigned id, uint64_t &count, double &time_ms) const
Definition
CustomBenchmark.h:81
count
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Definition
hcg.cxx:148
main
int main()
Definition
hello.cxx:18
Generated on
for ATLAS Offline Software by
1.17.0