ATLAS Offline Software
Loading...
Searching...
No Matches
custombenchmark_example.cxx File Reference
#include "PmbCxxUtils/CustomBenchmark.h"
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cmath>
Include dependency graph for custombenchmark_example.cxx:

Go to the source code of this file.

Functions

int main (int, char **)

Function Documentation

◆ main()

int main ( int ,
char **  )

Definition at line 15 of file custombenchmark_example.cxx.

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 {
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}
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146