diff --git a/include/internal/catch_timer.h b/include/internal/catch_timer.h index 6e8cf089..81b9fdb7 100644 --- a/include/internal/catch_timer.h +++ b/include/internal/catch_timer.h @@ -13,14 +13,14 @@ namespace Catch { class Timer { public: - Timer() : m_ticks( 0 ) {} + Timer() : m_microSeconds( 0 ) {} void start(); unsigned int getElapsedMicroseconds() const; unsigned int getElapsedMilliseconds() const; double getElapsedSeconds() const; private: - uint64_t m_ticks; + uint64_t m_microSeconds; }; } // namespace Catch diff --git a/include/internal/catch_timer.hpp b/include/internal/catch_timer.hpp index 52de3e83..d4066fa9 100644 --- a/include/internal/catch_timer.hpp +++ b/include/internal/catch_timer.hpp @@ -7,46 +7,22 @@ */ #include "catch_timer.h" -#include "catch_platform.h" -#ifdef CATCH_PLATFORM_WINDOWS - -# include "catch_windows_h_proxy.h" - -#else - -#include - -#endif +#include namespace Catch { namespace { -#ifdef CATCH_PLATFORM_WINDOWS - uint64_t getCurrentTicks() { - static uint64_t hz=0, hzo=0; - if (!hz) { - QueryPerformanceFrequency( reinterpret_cast( &hz ) ); - QueryPerformanceCounter( reinterpret_cast( &hzo ) ); - } - uint64_t t; - QueryPerformanceCounter( reinterpret_cast( &t ) ); - return ((t-hzo)*1000000)/hz; + uint64_t getCurrentMicrosecondsSinceEpoch() { + return std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); } -#else - uint64_t getCurrentTicks() { - timeval t; - gettimeofday(&t,nullptr); - return static_cast( t.tv_sec ) * 1000000ull + static_cast( t.tv_usec ); - } -#endif } void Timer::start() { - m_ticks = getCurrentTicks(); + m_microSeconds = getCurrentMicrosecondsSinceEpoch(); } unsigned int Timer::getElapsedMicroseconds() const { - return static_cast(getCurrentTicks() - m_ticks); + return static_cast(getCurrentMicrosecondsSinceEpoch() - m_microSeconds); } unsigned int Timer::getElapsedMilliseconds() const { return static_cast(getElapsedMicroseconds()/1000);