AmpGen
2.1
Toggle main menu visibility
Loading...
Searching...
No Matches
ProfileClock.h
Go to the documentation of this file.
1
#ifndef AMPGEN_PROFILECLOCK_H
2
#define AMPGEN_PROFILECLOCK_H 1
3
#include <chrono>
4
#include <cmath>
5
#include "
AmpGen/MsgService.h
"
6
#include "
AmpGen/Utilities.h
"
7
8
namespace
AmpGen
{
9
struct
ProfileClock
{
10
std::chrono::time_point<std::chrono::high_resolution_clock>
t_start
;
11
std::chrono::time_point<std::chrono::high_resolution_clock>
t_end
;
12
double
t_duration
= {0};
13
14
ProfileClock
() :
t_start
(std::chrono::high_resolution_clock::now()) {}
15
void
stop
() {
16
t_end
= std::chrono::high_resolution_clock::now();
17
t_duration
+= std::chrono::duration<double, std::milli>(
t_end
-
t_start
).count();
18
}
19
double
count
()
const
{
20
auto
now = std::chrono::high_resolution_clock::now();
21
return
std::chrono::duration<double, std::milli>(now -
t_start
).count();
22
}
23
void
start
() {
t_start
= std::chrono::high_resolution_clock::now(); }
24
operator
double()
const
{
return
t_duration
; };
25
};
26
27
template
<
int
N,
class
FCN>
double
Profile
(
const
FCN &
fcn
,
const
std::string &name =
""
) {
28
ProfileClock
t;
29
for
(
size_t
i = 0; i < N; ++i)
fcn
();
30
t.
stop
();
31
INFO
((name ==
""
?
type_string<FCN>
() : name) <<
" "
<< t /
double
(N) <<
"[ms] per iteration"
);
32
return
t;
33
}
34
template
<
int
N,
class
FCN>
double
ProfileWithStat
(
const
FCN &
fcn
,
const
std::string &name =
""
) {
35
double
t = 0;
36
double
t2 = 0;
37
double
tmin = 1e9;
38
double
tmax = 0;
39
for
(
size_t
i = 0; i < N; ++i) {
40
ProfileClock
pi;
41
fcn
();
42
pi.
stop
();
43
t += pi;
44
t2 += pi * pi;
45
tmin = pi < tmin ? pi : tmin;
46
tmax = pi > tmax ? pi : tmax;
47
}
48
t /= double(N);
49
t2 = std::sqrt(t2 /
double
(N) - t * t);
50
INFO
((name ==
""
?
type_string<FCN>
() : name) <<
" "
<< t <<
" ± "
<< t2 <<
"[ms] per iteration << ["
<< tmin <<
", "
<< tmax <<
"]"
);
51
return
t;
52
}
53
54
template
<
int
N,
class
FCN>
double
Profile2
(
const
FCN &
fcn
) {
55
ProfileClock
t;
56
auto
z = 0;
57
for
(
size_t
i = 0; i < N; ++i) z +=
fcn
();
58
t.
stop
();
59
INFO
(
type_string<FCN>
() <<
" "
<< t /
double
(N) <<
"[ms] per iteration; "
<< z);
60
return
t;
61
}
62
}
63
#endif
MsgService.h
Utilities.h
INFO
#define INFO(X)
Used for printing information messages, and will always be printed.
Definition
MsgService.h:81
AmpGen::fcn
Definition
Expression.h:464
AmpGen
Definition
AddCPConjugate.h:2
AmpGen::ProfileWithStat
double ProfileWithStat(const FCN &fcn, const std::string &name="")
Definition
ProfileClock.h:34
AmpGen::Profile
double Profile(const FCN &fcn, const std::string &name="")
Definition
ProfileClock.h:27
AmpGen::type_string
std::string type_string()
Utility classes for compile-time metaprogramming, such as identifying the types of arguments for gene...
Definition
MetaUtils.h:17
AmpGen::Profile2
double Profile2(const FCN &fcn)
Definition
ProfileClock.h:54
AmpGen::ProfileClock
Definition
ProfileClock.h:9
AmpGen::ProfileClock::ProfileClock
ProfileClock()
Definition
ProfileClock.h:14
AmpGen::ProfileClock::stop
void stop()
Definition
ProfileClock.h:15
AmpGen::ProfileClock::count
double count() const
Definition
ProfileClock.h:19
AmpGen::ProfileClock::t_end
std::chrono::time_point< std::chrono::high_resolution_clock > t_end
Definition
ProfileClock.h:11
AmpGen::ProfileClock::t_duration
double t_duration
Definition
ProfileClock.h:12
AmpGen::ProfileClock::t_start
std::chrono::time_point< std::chrono::high_resolution_clock > t_start
Definition
ProfileClock.h:10
AmpGen::ProfileClock::start
void start()
Definition
ProfileClock.h:23
AmpGen
ProfileClock.h
Generated on
for AmpGen by
1.17.0