-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.hpp
44 lines (35 loc) · 984 Bytes
/
Timer.hpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Timer.hpp
//
// Created by rick gessner on 5/25/19.
// Copyright © 2019 rick gessner. All rights reserved.
//
#ifndef Timer_h
#define Timer_h
#include <chrono>
namespace ECE141 {
class Timer {
public:
Timer() {
stopped=started=std::chrono::high_resolution_clock::now();
};
Timer& start() {
started=std::chrono::high_resolution_clock::now();
return *this;
}
Timer& stop() {
stopped=std::chrono::high_resolution_clock::now();
return *this;
}
double elapsed() {
if(started!=stopped) {
std::chrono::duration<double> elapsed = stopped - started;
return elapsed.count();
}
return 0.0;
}
std::chrono::time_point<std::chrono::high_resolution_clock> started;
std::chrono::time_point<std::chrono::high_resolution_clock> stopped;
};
}
#endif /* Timer_h */