3 #if defined(__APPLE__) && !defined(__unix__)
12 #ifdef CLOCK_MONOTONIC
13 unsigned long get_time_msec(void)
16 static struct timespec ts0;
18 clock_gettime(CLOCK_MONOTONIC, &ts);
19 if(ts0.tv_sec == 0 && ts0.tv_nsec == 0) {
23 return (ts.tv_sec - ts0.tv_sec) * 1000 + (ts.tv_nsec - ts0.tv_nsec) / 1000000;
25 #else /* no fancy POSIX clocks, fallback to good'ol gettimeofday */
26 unsigned long get_time_msec(void)
29 static struct timeval tv0;
32 if(tv0.tv_sec == 0 && tv0.tv_usec == 0) {
36 return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
38 #endif /* !posix clock */
40 void sleep_msec(unsigned long msec)
48 #pragma comment(lib, "winmm.lib")
50 unsigned long get_time_msec(void)
55 void sleep_msec(unsigned long msec)
61 double get_time_sec(void)
63 return get_time_msec() / 1000.0f;
66 void sleep_sec(double sec)
69 sleep_msec(sec * 1000.0f);
82 start_time = get_time_msec();
89 start_time += get_time_msec() - pause_time;
97 pause_time = get_time_msec();
101 bool Timer::is_running() const
103 return pause_time == 0;
106 unsigned long Timer::get_msec() const
109 // in paused state...
110 return pause_time - start_time;
112 return get_time_msec() - start_time;
115 double Timer::get_sec() const
117 return (double)get_msec() / 1000.0;