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