From 38071422d4874cdd98efa2747c1e053466d3ac22 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Thu, 26 Mar 2020 21:42:24 +0100
Subject: [PATCH] [BL] Use std::chrono::system_clock for wall-clock.

---
 BaseLib/RunTime.h | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/BaseLib/RunTime.h b/BaseLib/RunTime.h
index a1242234e31..532f8ee8a71 100644
--- a/BaseLib/RunTime.h
+++ b/BaseLib/RunTime.h
@@ -14,14 +14,10 @@
 
 #pragma once
 
-#if defined(USE_MPI)
+#ifdef USE_MPI
 #include <mpi.h>
 #else
-#ifndef WIN32
-#include <sys/time.h>
-#else
-#include <windows.h>
-#endif
+#include <chrono>
 #endif
 
 namespace BaseLib
@@ -34,37 +30,30 @@ class RunTime
         /// Start the timer.
         void start()
         {
-#if defined(USE_MPI)
+#ifdef USE_MPI
             _start_time = MPI_Wtime();
 #else
-#ifndef WIN32
-            timeval t;
-            gettimeofday(&t, nullptr);
-            _start_time = t.tv_sec + t.tv_usec/1000000.0;
-#else
-            _start_time = timeGetTime();
-#endif
+            _start_time = std::chrono::system_clock::now();
 #endif
         }
 
-        /// Get the elapsed time after started.
+        /// Get the elapsed time in seconds.
         double elapsed() const
         {
-#if defined(USE_MPI)
+#ifdef USE_MPI
             return MPI_Wtime() - _start_time;
 #else
-#ifndef WIN32
-            timeval t;
-            gettimeofday(&t, nullptr);
-            return t.tv_sec + t.tv_usec/1000000.0 - _start_time;
-#else
-            return (timeGetTime() - _start_time)/1000.0;
-#endif
+            using namespace std::chrono;
+            return duration<double>(system_clock::now() - _start_time).count();
 #endif
         }
 
     private:
-        double _start_time = 0.;
+#ifdef USE_MPI
+        double _start_time = std::numeric_limits<double>::quiet_NaN();
+#else
+        std::chrono::time_point<std::chrono::system_clock> _start_time;
+#endif
 };
 
 } // end namespace BaseLib
-- 
GitLab