Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Made most of Timer class inline - and export getCurrentMicrosecondsSinceEpoch()

Commit
c7028f7bc76e011f23fcc2baf308f5c27ef1f019
Author
Phil Nash ·
Parents
5450de2acd29

Files · Download .tar.gz

Changes

 include/internal/catch_timer.cpp | 19 ++-----------------
 include/internal/catch_timer.h   | 23 ++++++++++++++++-------
 2 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/include/internal/catch_timer.cpp b/include/internal/catch_timer.cpp
index d4066fa9..3253f1f4 100644
--- a/include/internal/catch_timer.cpp
+++ b/include/internal/catch_timer.cpp
@@ -12,23 +12,8 @@
 
 namespace Catch {
 
-    namespace {
-        uint64_t getCurrentMicrosecondsSinceEpoch() {
-            return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
-        }
-    }
-
-    void Timer::start() {
-        m_microSeconds = getCurrentMicrosecondsSinceEpoch();
-    }
-    unsigned int Timer::getElapsedMicroseconds() const {
-        return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds);
-    }
-    unsigned int Timer::getElapsedMilliseconds() const {
-        return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
-    }
-    double Timer::getElapsedSeconds() const {
-        return getElapsedMicroseconds()/1000000.0;
+    auto getCurrentMicrosecondsSinceEpoch() -> uint64_t {
+        return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
     }
 
 } // namespace Catch
diff --git a/include/internal/catch_timer.h b/include/internal/catch_timer.h
index 60115c80..2533b02f 100644
--- a/include/internal/catch_timer.h
+++ b/include/internal/catch_timer.h
@@ -11,15 +11,24 @@
 #include <stdint.h>
 
 namespace Catch {
-    class Timer {
-    public:
-        void start();
-        unsigned int getElapsedMicroseconds() const;
-        unsigned int getElapsedMilliseconds() const;
-        double getElapsedSeconds() const;
 
-    private:
+    auto getCurrentMicrosecondsSinceEpoch() -> uint64_t;
+
+    class Timer {
         uint64_t m_microSeconds = 0;
+    public:
+        void start() {
+           m_microSeconds = getCurrentMicrosecondsSinceEpoch();
+        }
+        auto getElapsedMicroseconds() const -> unsigned int {
+            return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds);
+        }
+        auto getElapsedMilliseconds() const -> unsigned int {
+            return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
+        }
+        auto getElapsedSeconds() const -> double {
+            return getElapsedMicroseconds()/1000000.0;
+        }
     };
 
 } // namespace Catch