21 gu_timeval_diff (
struct timeval* left,
struct timeval* right)
23 register long long diff = left->tv_sec;
24 diff = ((diff - right->tv_sec)*1000000LL) + left->tv_usec - right->tv_usec;
25 return (((
double)diff) * 1.0e-06);
29 gu_timeval_add (
struct timeval* t,
double s)
31 double ret = (double)t->tv_sec + ((
double)t->tv_usec) * 1.0e-06 + s;
33 t->tv_sec = (long)ret;
34 t->tv_usec = (long)((ret - (
double)t->tv_sec) * 1.0e+06);
37 static const double SEC_PER_CLOCK = ((double)1.0)/CLOCKS_PER_SEC;
41 gu_clock_diff (clock_t left, clock_t right)
43 return ((
double)(left - right)) * SEC_PER_CLOCK;
46 #include "gu_limits.h"
56 #define GU_TIME_ETERNITY 9223372035999999999LL
58 #if defined(__APPLE__)
59 # define CLOCK_REALTIME 0
60 # define CLOCK_MONOTONIC 1
61 typedef int clockid_t;
62 int clock_gettime (clockid_t clk_id,
struct timespec * tp);
65 static inline long long
70 clock_getres (CLOCK_REALTIME, &tmp);
71 return ((tmp.tv_sec * 1000000000LL) + tmp.tv_nsec);
77 static inline long long
80 #if _POSIX_TIMERS > 0 || defined(__APPLE__)
82 clock_gettime (CLOCK_REALTIME, &tmp);
83 return ((tmp.tv_sec * 1000000000LL) + tmp.tv_nsec);
86 gettimeofday (&tmp, NULL);
87 return ((tmp.tv_sec * 1000000000LL) + (tmp.tv_usec * 1000LL));
91 static inline long long
94 #if defined(_POSIX_MONOTONIC_CLOCK) || defined(__APPLE__)
96 clock_gettime (CLOCK_MONOTONIC, &tmp);
97 return ((tmp.tv_sec * 1000000000LL) + tmp.tv_nsec);
100 gettimeofday (&tmp, NULL);
101 return ((tmp.tv_sec * 1000000000LL) + (tmp.tv_usec * 1000LL));
105 #ifdef CLOCK_PROCESS_CPUTIME_ID
106 static inline long long
107 gu_time_process_cputime()
109 #if _POSIX_TIMERS > 0
111 clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tmp);
112 return ((tmp.tv_sec * 1000000000LL) + tmp.tv_nsec);
120 static inline long long
121 gu_time_thread_cputime()
123 #if _POSIX_TIMERS > 0
125 clock_gettime (CLOCK_THREAD_CPUTIME_ID, &tmp);
126 return ((tmp.tv_sec * 1000000000LL) + tmp.tv_nsec);