proxsuite
0.6.7
The Advanced Proximal Optimization Toolbox
Loading...
Searching...
No Matches
timings.hpp
Go to the documentation of this file.
1
//
2
// Copyright (c) 2022 INRIA
3
//
4
5
#ifndef PROXSUITE_PROXQP_TIMINGS_HPP
6
#define PROXSUITE_PROXQP_TIMINGS_HPP
7
8
#include <chrono>
9
10
namespace
proxsuite
{
11
namespace
proxqp
{
12
13
struct
CPUTimes
14
{
15
double
wall
;
16
double
user
;
17
double
system
;
18
19
CPUTimes
()
20
:
wall
(0)
21
,
user
(0)
22
,
system
(0)
23
{
24
}
25
26
void
clear
() {
wall
=
user
=
system
= 0; }
27
};
28
34
template
<
typename
T>
35
struct
Timer
36
{
37
Timer
()
38
:
m_is_stopped
(true)
39
{
40
start
();
41
}
42
43
CPUTimes
elapsed
()
const
44
{
45
if
(
m_is_stopped
)
46
return
m_times
;
47
48
CPUTimes
current(
m_times
);
49
std::chrono::time_point<std::chrono::steady_clock> current_clock =
50
std::chrono::steady_clock::now();
51
current.
user
+=
52
static_cast<
T
>
(std::chrono::duration_cast<std::chrono::nanoseconds>(
53
current_clock -
m_start
)
54
.count()) *
55
1e-3;
56
57
return
current;
58
}
59
60
void
start
()
61
{
62
if
(
m_is_stopped
) {
63
m_is_stopped
=
false
;
64
m_times
.
clear
();
65
m_start
= std::chrono::steady_clock::now();
66
}
67
}
68
69
void
stop
()
70
{
71
if
(
m_is_stopped
)
72
return
;
73
m_is_stopped
=
true
;
74
75
m_end
= std::chrono::steady_clock::now();
76
m_times
.
user
+=
77
static_cast<
double
>
(
78
std::chrono::duration_cast<std::chrono::nanoseconds>(
m_end
-
m_start
)
79
.count()) *
80
1e-3;
81
}
82
83
void
resume
()
84
{
85
if
(
m_is_stopped
)
86
m_start
= std::chrono::steady_clock::now();
87
}
88
89
bool
is_stopped
()
const
{
return
m_is_stopped
; }
90
91
protected
:
92
CPUTimes
m_times
;
93
bool
m_is_stopped
;
94
95
std::chrono::time_point<std::chrono::steady_clock>
m_start
,
m_end
;
96
};
97
98
}
// namespace proxqp
99
}
// namespace proxsuite
100
101
#endif
// ifndef PROXSUITE_PROXQP_TIMINGS_HPP
proxsuite::proxqp
Definition
backward_data.hpp:16
proxsuite
Definition
common.hpp:14
proxsuite::proxqp::CPUTimes
Definition
timings.hpp:14
proxsuite::proxqp::CPUTimes::CPUTimes
CPUTimes()
Definition
timings.hpp:19
proxsuite::proxqp::CPUTimes::user
double user
Definition
timings.hpp:16
proxsuite::proxqp::CPUTimes::system
double system
Definition
timings.hpp:17
proxsuite::proxqp::CPUTimes::clear
void clear()
Definition
timings.hpp:26
proxsuite::proxqp::CPUTimes::wall
double wall
Definition
timings.hpp:15
proxsuite::proxqp::Timer
This class mimics the way "boost/timer/timer.hpp" operates while using the modern std::chrono library...
Definition
timings.hpp:36
proxsuite::proxqp::Timer::start
void start()
Definition
timings.hpp:60
proxsuite::proxqp::Timer::m_end
std::chrono::time_point< std::chrono::steady_clock > m_end
Definition
timings.hpp:95
proxsuite::proxqp::Timer::elapsed
CPUTimes elapsed() const
Definition
timings.hpp:43
proxsuite::proxqp::Timer::resume
void resume()
Definition
timings.hpp:83
proxsuite::proxqp::Timer::m_start
std::chrono::time_point< std::chrono::steady_clock > m_start
Definition
timings.hpp:95
proxsuite::proxqp::Timer::is_stopped
bool is_stopped() const
Definition
timings.hpp:89
proxsuite::proxqp::Timer::m_times
CPUTimes m_times
Definition
timings.hpp:92
proxsuite::proxqp::Timer::stop
void stop()
Definition
timings.hpp:69
proxsuite::proxqp::Timer::m_is_stopped
bool m_is_stopped
Definition
timings.hpp:93
proxsuite::proxqp::Timer::Timer
Timer()
Definition
timings.hpp:37
include
proxsuite
proxqp
timings.hpp
Generated by
1.10.0