Add timer
This commit is contained in:
parent
8008d9c58d
commit
07db01e3eb
|
@ -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();
|
||||
}
|
||||
|
|
@ -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
|
Loading…
Reference in New Issue