diff options
| author | Phil Nash | 2017-08-04 12:22:16 +0100 |
|---|---|---|
| committer | Phil Nash | 2017-08-04 12:22:16 +0100 |
| commit | 39d37d9f341e0cefc52a2abfdefbe1071fe0bc56 (patch) | |
| tree | 3cda55e7739737e42beeaf8981a561df6fdf6861 /include/internal | |
| parent | c7028f7bc76e011f23fcc2baf308f5c27ef1f019 (diff) | |
| download | catch3-39d37d9f341e0cefc52a2abfdefbe1071fe0bc56.tar.gz | |
Timer resolution is now nanoseconds
Diffstat (limited to 'include/internal')
| -rw-r--r-- | include/internal/catch_timer.cpp | 4 | ||||
| -rw-r--r-- | 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); |