Biorbd
Release_1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Timer.cpp
1
#define BIORBD_API_EXPORTS
2
#include "Utils/Timer.h"
3
4
using namespace
BIORBD_NAMESPACE;
5
6
utils::Timer::Timer
(
bool
startNow)
7
:
m_isStarted
(false),
8
m_isPaused
(false),
9
m_start
(),
10
m_pauseTime
(),
11
m_totalPauseTime
(0.0) {
12
if
(startNow) {
13
start
();
14
}
15
}
16
17
void
utils::Timer::start
() {
18
m_start
= std::clock();
19
m_totalPauseTime
= 0;
20
m_isPaused
=
false
;
21
m_isStarted
=
true
;
22
}
// Start a timer
23
24
bool
utils::Timer::isStarted
() {
return
m_isStarted
; }
25
26
void
utils::Timer::pause
() {
27
if
(!
m_isPaused
) {
28
m_isPaused
=
true
;
29
m_pauseTime
= std::clock();
30
}
31
}
32
33
void
utils::Timer::resume
() {
34
if
(!
m_isStarted
) {
35
start
();
36
}
37
38
else
if
(
m_isPaused
) {
39
addPauseTime
();
40
m_isPaused
=
false
;
41
}
42
}
43
44
double
utils::Timer::getLap
() {
45
addPauseTime
();
46
47
if
(
m_isStarted
) {
48
return
getTime
(
m_start
) -
m_totalPauseTime
;
49
}
else
{
50
return
0;
51
}
52
}
53
54
double
utils::Timer::stop
() {
55
if
(
m_isStarted
) {
56
m_isStarted
=
false
;
57
return
getLap
();
58
}
else
{
59
return
0;
60
}
61
}
62
63
void
utils::Timer::addPauseTime
() {
64
if
(
m_isPaused
) {
65
m_totalPauseTime
+=
getTime
(
m_pauseTime
);
66
m_pauseTime
= std::clock();
67
}
68
}
69
70
double
utils::Timer::getTime
(
const
std::clock_t& timer) {
71
return
static_cast<
double
>
(std::clock() - timer) / CLOCKS_PER_SEC;
72
}
BIORBD_NAMESPACE::utils::Timer::getTime
double getTime(const std::clock_t &timer)
Get the time spent until start.
Definition
Timer.cpp:70
BIORBD_NAMESPACE::utils::Timer::isStarted
bool isStarted()
Return if the timer is started.
Definition
Timer.cpp:24
BIORBD_NAMESPACE::utils::Timer::Timer
Timer(bool startNow=false)
Construct timer.
Definition
Timer.cpp:6
BIORBD_NAMESPACE::utils::Timer::m_pauseTime
std::clock_t m_pauseTime
The pause time.
Definition
Timer.h:74
BIORBD_NAMESPACE::utils::Timer::m_isPaused
bool m_isPaused
If the timer is paused.
Definition
Timer.h:72
BIORBD_NAMESPACE::utils::Timer::m_isStarted
bool m_isStarted
If the timer is started.
Definition
Timer.h:71
BIORBD_NAMESPACE::utils::Timer::start
void start()
Start the timer.
Definition
Timer.cpp:17
BIORBD_NAMESPACE::utils::Timer::resume
void resume()
Resume the timer. If it is paused, it adds a lap.
Definition
Timer.cpp:33
BIORBD_NAMESPACE::utils::Timer::getLap
double getLap()
Get the lap time of a running timer. Return 0 if the timer is not running.
Definition
Timer.cpp:44
BIORBD_NAMESPACE::utils::Timer::addPauseTime
void addPauseTime()
Add a pause to the timer time (total time being execution time - pause time).
Definition
Timer.cpp:63
BIORBD_NAMESPACE::utils::Timer::m_start
std::clock_t m_start
The start time.
Definition
Timer.h:73
BIORBD_NAMESPACE::utils::Timer::m_totalPauseTime
double m_totalPauseTime
The total pause time.
Definition
Timer.h:75
BIORBD_NAMESPACE::utils::Timer::stop
double stop()
Stop the timer and return the lap time.
Definition
Timer.cpp:54
BIORBD_NAMESPACE::utils::Timer::pause
void pause()
Pause the timer.
Definition
Timer.cpp:26
src
Utils
Timer.cpp
Generated by
1.18.0