diff --git a/docs/changes.txt b/docs/changes.txt index 68cf93d967..fc1a6a4837 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -459,7 +459,8 @@ All: - Fix crash in wxArray::insert() overload taking iterator range (wsu). - Added wxEventFilter class and wxEvtHandler::{Add,Remove}Filter(). - Added convenient wxCmdLineParser::AddLong{Option,Switch}() wrappers. -- Added wxStopWatch::TimeInMicro() and wxGetUTCTimeUSec(). +- Added wxStopWatch::TimeInMicro() and wxGetUTCTimeUSec() and improved + wxStopWatch precision. - Made wxGetLocalTimeMillis() really return local time, added wxGetUTCTimeMillis() returning what this function used to return. diff --git a/src/common/stopwatch.cpp b/src/common/stopwatch.cpp index b0e6ddde40..f077378b3a 100644 --- a/src/common/stopwatch.cpp +++ b/src/common/stopwatch.cpp @@ -112,8 +112,15 @@ wxLongLong wxStopWatch::GetClockFreq() const return gs_perfCounter.freq.QuadPart; #endif // __WXMSW__ +#ifdef HAVE_GETTIMEOFDAY + // With gettimeofday() we can have nominally microsecond precision and + // while this is not the case in practice, it's still better than + // millisecond. + return MICROSECONDS_PER_SECOND; +#else // !HAVE_GETTIMEOFDAY // Currently milliseconds are used everywhere else. return MILLISECONDS_PER_SECOND; +#endif // HAVE_GETTIMEOFDAY/!HAVE_GETTIMEOFDAY } void wxStopWatch::Start(long t0) @@ -134,7 +141,11 @@ wxLongLong wxStopWatch::GetCurrentClockValue() const } #endif // __WXMSW__ +#ifdef HAVE_GETTIMEOFDAY + return wxGetUTCTimeUSec(); +#else // !HAVE_GETTIMEOFDAY return wxGetUTCTimeMillis(); +#endif // HAVE_GETTIMEOFDAY/!HAVE_GETTIMEOFDAY } wxLongLong wxStopWatch::TimeInMicro() const