Added timer

This commit is contained in:
2022-04-23 18:30:16 +03:00
parent c2e0400d88
commit 3c721273c0
3 changed files with 45 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
#include "timer.h"
BEGIN_NAMESPACE
timer::timer() {
start_time = std::chrono::system_clock::now();
last_lap_time = start_time;
}
double timer::seconds_since_start() {
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = now - start_time;
return elapsed_seconds.count();
}
double timer::lap() {
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = now - last_lap_time;
last_lap_time = now;
return elapsed_seconds.count();
}
END_NAMESPACE