The Gaudi Framework
master (1bab3404)
Toggle main menu visibility
Loading...
Searching...
No Matches
TimingAlg.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#include <
GaudiKernel/Algorithm.h
>
12
#include <
GaudiKernel/Chrono.h
>
13
#include <
GaudiKernel/IRndmGenSvc.h
>
14
#include <
GaudiKernel/RndmGenerators.h
>
15
#include <boost/format.hpp>
16
#include <cmath>
17
18
namespace
GaudiTestSuite
{
29
class
TimingAlg
:
public
Algorithm
{
30
public
:
31
using
Algorithm::Algorithm
;
32
StatusCode
execute
()
override
;
33
StatusCode
finalize
()
override
;
34
35
protected
:
37
double
doSomething
();
38
39
private
:
41
Gaudi::Property<unsigned long>
m_cycles
{
this
,
"Cycles"
, 10000,
"The number of cycles"
};
42
43
private
:
44
ChronoEntity
m_chrono1
;
45
ChronoEntity
m_chrono2
;
46
ChronoEntity
m_chrono3
;
47
};
48
double
TimingAlg::doSomething
() {
49
double
result = 0;
50
Rndm::Numbers
gauss(
randSvc
(),
Rndm::Gauss
( 0.0, 1.0 ) );
51
for
(
unsigned
long
i = 0; i <
m_cycles
; ++i ) result += sin( gauss() );
52
return
result;
53
}
54
StatusCode
TimingAlg::execute
() {
55
{
// make some cpu consuming evaluations:
56
Chrono
chrono(
chronoSvc
(),
name
() +
": the first loop"
);
57
debug
() <<
"the result of the first loop is "
<<
doSomething
() <<
endmsg
;
58
}
59
{
// make some cpu consuming evaluations:
60
Chrono
chrono(
name
() +
": the second loop"
,
chronoSvc
() );
61
debug
() <<
"the result of the second loop is "
<<
doSomething
() <<
endmsg
;
62
}
63
{
// make some cpu consuming evaluations:
64
Chrono
chrono( &
m_chrono1
);
65
debug
() <<
"the result of the third loop is "
<<
doSomething
() <<
endmsg
;
66
}
67
{
// make some cpu consuming evaluations:
68
Chrono
chrono(
m_chrono2
);
69
debug
() <<
"the result of the fourth loop is "
<<
doSomething
() <<
endmsg
;
70
}
71
{
// make some cpu consuming evaluations:
72
m_chrono3
.start();
73
debug
() <<
"the result of the 5th loop is "
<<
doSomething
() <<
endmsg
;
74
m_chrono3
.stop();
75
}
76
{
// make some cpu consuming evaluations:
77
chronoSvc
()->chronoStart(
name
() +
": the 5th loop"
);
78
debug
() <<
"the result of the 5th loop is "
<<
doSomething
() <<
endmsg
;
79
chronoSvc
()->chronoStop(
name
() +
": the 5th loop"
);
80
}
81
return
StatusCode::SUCCESS
;
82
}
83
84
StatusCode
TimingAlg::finalize
() {
85
const
std::string
format
=
"| %1$-6d| %2$-12.5g| %3$12.5g+-%4$-12.5g|%6$12.5g/%7$-12.5g|"
;
86
const
std::string header =
"| |%1$=7.7s|%2$=13.13s|%3$13.13s+-%4$-12.12s|%6$12.12g/%7$-12.12s|"
;
87
88
using namespace
boost::io;
89
boost::format hdr( header );
90
hdr.exceptions( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) );
91
92
hdr %
"#"
%
"Total"
%
"Mean"
%
"RMS"
%
"ErrMean"
%
"Min"
%
"Max"
;
93
94
always
() <<
"The timing is (in us)"
<< std::endl
95
<< hdr.str() << std::endl
96
<<
"| (1U) "
<<
m_chrono1
.outputUserTime(
format
,
System::microSec
) << std::endl
97
<<
"| (2U) "
<<
m_chrono2
.outputUserTime(
format
,
System::microSec
) << std::endl
98
<<
"| (3U) "
<<
m_chrono3
.outputUserTime(
format
,
System::microSec
) <<
endmsg
;
99
100
return
Algorithm::finalize
();
101
}
102
103
DECLARE_COMPONENT
(
TimingAlg
)
104
}
// end of namespace GaudiTestSuite
Chrono.h
Algorithm.h
IRndmGenSvc.h
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition
MsgStream.cpp:93
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition
PluginServiceV1.h:45
RndmGenerators.h
ChronoEntity
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition
ChronoEntity.h:26
Chrono
A small utility class for chronometry of user codes.
Definition
Chrono.h:27
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition
CommonMessaging.h:118
CommonMessagingBase::always
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition
CommonMessaging.h:100
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition
Algorithm.h:98
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition
Algorithm.h:181
Gaudi::Algorithm::chronoSvc
SmartIF< IChronoStatSvc > & chronoSvc() const
The standard Chrono & Stat service, Return a pointer to the service if present.
Definition
Algorithm.cpp:548
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition
Algorithm.cpp:555
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition
Algorithm.cpp:518
Gaudi::Property
Implementation of property with value of concrete type.
Definition
Property.h:35
GaudiTestSuite::TimingAlg
The primitive class to illustrate the usage of IChronoSvc , ChronoEntity & Chrono objects.
Definition
TimingAlg.cpp:29
GaudiTestSuite::TimingAlg::m_chrono2
ChronoEntity m_chrono2
Definition
TimingAlg.cpp:45
GaudiTestSuite::TimingAlg::m_chrono1
ChronoEntity m_chrono1
Definition
TimingAlg.cpp:44
GaudiTestSuite::TimingAlg::doSomething
double doSomething()
do something CPU-intensive
Definition
TimingAlg.cpp:48
GaudiTestSuite::TimingAlg::m_chrono3
ChronoEntity m_chrono3
Definition
TimingAlg.cpp:46
GaudiTestSuite::TimingAlg::execute
StatusCode execute() override
Definition
TimingAlg.cpp:54
GaudiTestSuite::TimingAlg::m_cycles
Gaudi::Property< unsigned long > m_cycles
the length of the internal loops (property)
Definition
TimingAlg.cpp:41
GaudiTestSuite::TimingAlg::finalize
StatusCode finalize() override
Definition
TimingAlg.cpp:84
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition
RndmGenerators.h:27
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition
RndmGenerators.h:354
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
GaudiTestSuite
Definition
LoggingAuditor.cpp:21
System::microSec
@ microSec
Definition
Timing.h:45
GaudiTestSuite
src
Timing
TimingAlg.cpp
Generated on
for The Gaudi Framework by
1.17.0