]> git.saurik.com Git - wxWidgets.git/commitdiff
Use wxGetUTCTimeUSec() in wxStopWatch under Unix for higher precision.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 Nov 2011 19:50:42 +0000 (19:50 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 Nov 2011 19:50:42 +0000 (19:50 +0000)
If gettimeofday() is available we can achieve better than millisecond
precision (even if it usually isn't as high as microsecond), so use it as
clock source in wxStopWatch.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69841 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/common/stopwatch.cpp

index 68cf93d967e0d54eba5adaf8f5f3109d89ee8d78..fc1a6a4837d6df682d773f4591370e1fd95c7ead 100644 (file)
@@ -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.
 
index b0e6ddde4085cdb0fec25f6363485044e9735baf..f077378b3abaf5762e031d960d58e4a75a3000a3 100644 (file)
@@ -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