From 9a9a237272d96c4a605adaca7c2515e1c969d47a Mon Sep 17 00:00:00 2001 From: Etienne Renault Date: Wed, 4 May 2016 10:56:21 +0200 Subject: [PATCH] timer: support for walltime * spot/misc/timer.hh: here. --- spot/misc/timer.hh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spot/misc/timer.hh b/spot/misc/timer.hh index df045ac84..d60aaf3a2 100644 --- a/spot/misc/timer.hh +++ b/spot/misc/timer.hh @@ -33,7 +33,7 @@ # include #endif #include - +#include namespace spot { @@ -96,6 +96,7 @@ namespace spot { SPOT_ASSERT(!running); running = true; + wall_start_ = std::chrono::high_resolution_clock::now(); #ifdef SPOT_HAVE_TIMES struct tms tmp; times(&tmp); @@ -112,6 +113,9 @@ namespace spot void stop() { + auto end = std::chrono::high_resolution_clock::now(); + wall_cumul_ = std::chrono::duration_cast + (end - wall_start_).count(); #ifdef SPOT_HAVE_TIMES struct tms tmp; times(&tmp); @@ -194,10 +198,23 @@ namespace spot return running; } + /// \brief Return cumulative wall time + /// + /// When using multithreading the cpu time is not + /// relevant and we have to deal with wall time to have an + /// effective timer + std::chrono::milliseconds::rep + walltime() const + { + return wall_cumul_; + } + protected: time_info start_; time_info total_; bool running; + std::chrono::high_resolution_clock::time_point wall_start_; + std::chrono::milliseconds::rep wall_cumul_; }; // This function declared here must be implemented in each file