-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.hpp
37 lines (29 loc) · 1.02 KB
/
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
//
// Created by Andrew Yang on 3/27/21.
//
#ifndef RAYTRACING_TIMER_H
#define RAYTRACING_TIMER_H
#include <chrono>
class Timer {
public:
Timer() : start{std::chrono::high_resolution_clock::now()} {}
[[nodiscard]] unsigned get_millis() const {
const auto elapsed = std::chrono::high_resolution_clock::now() - start;
return std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
}
[[nodiscard]] unsigned get_seconds() const {
const auto elapsed = std::chrono::high_resolution_clock::now() - start;
return std::chrono::duration_cast<std::chrono::seconds>(elapsed).count();
}
[[nodiscard]] std::string to_string() const {
int n = (int)get_seconds();
int h = n / 3600;
n %= 3600;
int m = n / 60;
n %= 60;
return std::to_string(h) + " hours, " + std::to_string(m) + " minutes, " + std::to_string(n) + " seconds.\n";
}
private:
std::chrono::high_resolution_clock::time_point start;
};
#endif //RAYTRACING_TIMER_H