mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
Add small chrono timer object
This is just so if someone wants a quick way to measure how long something takes for benchmarking purposes they don't have to reinvent anything. See examples in comments
This commit is contained in:
parent
cb39a35f3f
commit
edc42bf5b6
@ -19,6 +19,7 @@
|
||||
#define TIMER_H
|
||||
|
||||
#include "types.h"
|
||||
#include <chrono>
|
||||
|
||||
// Disgrace: for windows compile
|
||||
#ifdef _WINDOWS
|
||||
@ -65,4 +66,28 @@ private:
|
||||
bool pUseAcurateTiming;
|
||||
};
|
||||
|
||||
/* Wrapper around chrono to make adding simple time based benching easy
|
||||
* ex:
|
||||
* void foo() {
|
||||
* ...
|
||||
* BenchTimer timer;
|
||||
* ... (expensive work here)
|
||||
* auto dur = timer.elapsed();
|
||||
* std::cout << "foo() took " << dur << seconds" << std::endl;
|
||||
* ...
|
||||
* }
|
||||
* */
|
||||
|
||||
struct BenchTimer
|
||||
{
|
||||
typedef std::chrono::high_resolution_clock clock;
|
||||
|
||||
BenchTimer() : start_time(clock::now()) {}
|
||||
void reset() { start_time = clock::now(); }
|
||||
// this is seconds
|
||||
double elapsed() { return std::chrono::duration<double> (clock::now() - start_time).count(); }
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user