-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.cpp
More file actions
26 lines (21 loc) · 794 Bytes
/
Clock.cpp
File metadata and controls
26 lines (21 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "Clock.h"
namespace df {
Clock::Clock() {
m_previous_time = std::chrono::steady_clock::now();
}
// Return elapsed microseconds since last delta() call, then reset timer.
long int Clock::delta() {
auto now = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(
now - m_previous_time).count();
m_previous_time = now; // reset
return static_cast<long int>(elapsed);
}
// Return elapsed microseconds since last delta() call WITHOUT resetting.
long int Clock::split() const {
auto now = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(
now - m_previous_time).count();
return static_cast<long int>(elapsed);
}
} // end namespace df