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

Timer resolution is now nanoseconds

Commit
39d37d9f341e0cefc52a2abfdefbe1071fe0bc56
Author
Phil Nash ·
Parents
c7028f7bc76e

Files · Download .tar.gz

Changes

 include/internal/catch_timer.cpp |  4 ++--
 include/internal/catch_timer.h   | 11 +++++++----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/include/internal/catch_timer.cpp b/include/internal/catch_timer.cpp
index 3253f1f4..fad86f85 100644
--- a/include/internal/catch_timer.cpp
+++ b/include/internal/catch_timer.cpp
@@ -12,8 +12,8 @@
 
 namespace Catch {
 
-    auto getCurrentMicrosecondsSinceEpoch() -> uint64_t {
-        return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
+    auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
+        return std::chrono::duration_cast<std::chrono::nanoseconds>( 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 2533b02f..d9c381c1 100644
--- a/include/internal/catch_timer.h
+++ b/include/internal/catch_timer.h
@@ -12,16 +12,19 @@
 
 namespace Catch {
 
-    auto getCurrentMicrosecondsSinceEpoch() -> uint64_t;
+    auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
 
     class Timer {
-        uint64_t m_microSeconds = 0;
+        uint64_t m_nanoseconds = 0;
     public:
         void start() {
-           m_microSeconds = getCurrentMicrosecondsSinceEpoch();
+           m_nanoseconds = getCurrentNanosecondsSinceEpoch();
+        }
+        auto getElapsedNanoseconds() const -> unsigned int {
+            return static_cast<unsigned int>(getCurrentNanosecondsSinceEpoch() - m_nanoseconds);
         }
         auto getElapsedMicroseconds() const -> unsigned int {
-            return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds);
+            return static_cast<unsigned int>(getElapsedNanoseconds()/1000);
         }
         auto getElapsedMilliseconds() const -> unsigned int {
             return static_cast<unsigned int>(getElapsedMicroseconds()/1000);