From 8a2b2e6700e214b2cd14d97b32d9b8215a1d0a62 Mon Sep 17 00:00:00 2001 From: heckflosse Date: Wed, 5 Oct 2016 01:15:52 +0200 Subject: [PATCH] Extended StopWatch class to report processing time in microseconds --- rtengine/StopWatch.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/rtengine/StopWatch.h b/rtengine/StopWatch.h index ac4a4d16c..9e4400b94 100644 --- a/rtengine/StopWatch.h +++ b/rtengine/StopWatch.h @@ -26,18 +26,17 @@ #ifdef BENCHMARK #define BENCHFUN StopWatch StopFun(__func__); + #define BENCHFUNMICRO StopWatch StopFun(__func__, true); #else #define BENCHFUN + #define BENCHFUNMICRO #endif class StopWatch { public: - StopWatch( ) - { - stopped = false; - } - explicit StopWatch( const char* msg ) + + explicit StopWatch( const char* msg, bool microseconds = false ) : microseconds(microseconds) { message = msg; start(); @@ -56,8 +55,13 @@ public: void stop() { stopTime.set(); - long elapsedTime = stopTime.etime(startTime) / 1000; - std::cout << message << " took " << elapsedTime << " ms" << std::endl; + if(!microseconds) { + long elapsedTime = stopTime.etime(startTime) / 1000; + std::cout << message << " took " << elapsedTime << " ms" << std::endl; + } else { + long elapsedTime = stopTime.etime(startTime); + std::cout << message << " took " << elapsedTime << " us" << std::endl; + } stopped = true; } void stop(const char *msg) @@ -66,6 +70,7 @@ public: stop(); }; private: + bool microseconds; MyTime startTime; MyTime stopTime; const char *message;