diff --git a/Core/src/StopWatchOSX.cpp b/Core/src/StopWatchOSX.cpp index 2aeb971..fda23cc 100644 --- a/Core/src/StopWatchOSX.cpp +++ b/Core/src/StopWatchOSX.cpp @@ -3,24 +3,20 @@ #include #include -#include +#include class StopWatchImpl { public: uint64 start; - - double resolution; - double duration; - - StopWatchImpl() { - mach_timebase_info_data_t info; - mach_timebase_info(&info); - - resolution = double(info.numer) / double(info.denom); - resolution *= 1e-9; - } + uint64 duration; }; +static uint64 Now() { + timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_usec + (1e6 * tv.tv_sec); +} + StopWatch::StopWatch(const StopWatch &other) { impl = new StopWatchImpl(); memcpy(impl, other.impl, sizeof(StopWatchImpl)); @@ -43,11 +39,11 @@ StopWatch::StopWatch() : impl(new StopWatchImpl) { } void StopWatch::Start() { - impl->start = mach_absolute_time(); + impl->start = Now(); } void StopWatch::Stop() { - impl->duration = impl->resolution * (double(mach_absolute_time()) - impl->start); + impl->duration = Now() - impl->start; } void StopWatch::Reset() { @@ -55,13 +51,13 @@ void StopWatch::Reset() { } double StopWatch::TimeInSeconds() const { - return impl->duration; + return double(impl->duration) / 1e6; } double StopWatch::TimeInMilliseconds() const { - return impl->duration * 1000; + return double(impl->duration) / 1e3; } double StopWatch::TimeInMicroseconds() const { - return impl->duration * 1000000; + return double(impl->duration); }