Commits

c...@visotech.at  committed a691434

using clock_gettime

  • Participants
  • Parent commits 0c55b8f

Comments (0)

Files changed (1)

 #error "This module requires gettimeofday() on non-Windows platforms!"
 #endif
 
-#if (defined(PYOS_OS2) && defined(PYCC_GCC))
 #include <sys/time.h>
-#else
-#include <sys/resource.h>
-#include <sys/times.h>
-#endif
+#include <time.h>
+
+#define MY_CLOCK CLOCK_MONOTONIC
 
 PY_LONG_LONG
 hpTimer(void)
 {
-        struct timeval tv;
-        PY_LONG_LONG ret;
-#ifdef GETTIMEOFDAY_NO_TZ
-        gettimeofday(&tv);
-#else
-        gettimeofday(&tv, (struct timezone *)NULL);
-#endif
-        ret = tv.tv_sec;
-        ret = ret * 1000000 + tv.tv_usec;
-        return ret;
+    struct timespec tp;
+    long err = clock_gettime(MY_CLOCK, &tp);
+    if (err)
+        return 0;
+
+    return tp.tv_sec * 1e9 + tp.tv_nsec;
 }
 
 double
 hpTimerUnit(void)
 {
-        return 0.000001;
+    struct timespec tp;
+    long err = clock_getres(MY_CLOCK, &tp);
+    if (err)
+        return 0.0;
+    return ((double)tp.tv_nsec) / 1e9;
 }
 
 #endif  /* MS_WINDOWS */