diff --git a/common/timer.h b/common/timer.h index 4b2719dc6..f06f5bbe4 100644 --- a/common/timer.h +++ b/common/timer.h @@ -19,6 +19,7 @@ #define TIMER_H #include "types.h" +#include // 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 (clock::now() - start_time).count(); } +private: + std::chrono::time_point start_time; +}; + #endif