Add timer

This commit is contained in:
realaltffour 2020-04-14 14:59:43 +03:00
parent 8008d9c58d
commit 07db01e3eb
No known key found for this signature in database
GPG Key ID: 7115CD2AC9A76A56
2 changed files with 38 additions and 0 deletions

18
src/timer.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "timer.h"
void timer_start() {
s_timer.isRunning = true;
s_timer.startTime = std::chrono::high_resolution_clock::now();
}
void timer_stop() {
s_timer.isRunning = false;
s_timer.endTime = std::chrono::high_resolution_clock::now();
}
float timer_get() {
std::chrono::duration<float> duration =
std::chrono::high_resolution_clock::now() - s_timer.startTime;
return duration.count();
}

20
src/timer.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef TIMER_H
#define TIMER_H
#include <atomic>
#include <chrono>
struct Timer {
std::chrono::time_point<std::chrono::high_resolution_clock> startTime;
std::chrono::time_point<std::chrono::high_resolution_clock> endTime;
bool isRunning = false;
};
static Timer s_timer;
void timer_start();
void timer_stop();
float timer_get();
#endif