17 gettimeofday(¤t_time, 0);
21 int64_t Timer::get_difference(struct timeval *result)
23 gettimeofday(&new_time, 0);
25 result->tv_usec = new_time.tv_usec - current_time.tv_usec;
26 result->tv_sec = new_time.tv_sec - current_time.tv_sec;
27 if(result->tv_usec < 0)
29 result->tv_usec += 1000000;
33 return (int64_t)result->tv_sec * 1000 + (int64_t)result->tv_usec / 1000;
36 int64_t Timer::get_difference()
38 gettimeofday(&new_time, 0);
40 new_time.tv_usec -= current_time.tv_usec;
41 new_time.tv_sec -= current_time.tv_sec;
42 if(new_time.tv_usec < 0)
44 new_time.tv_usec += 1000000;
48 return (int64_t)new_time.tv_sec * 1000 +
49 (int64_t)new_time.tv_usec / 1000;
52 int64_t Timer::get_scaled_difference(long denominator)
54 get_difference(&new_time);
55 return (int64_t)new_time.tv_sec * denominator +
56 (int64_t)((double)new_time.tv_usec / 1000000 * denominator);
59 int Timer::delay(long milliseconds)
61 struct timeval delay_duration;
62 delay_duration.tv_sec = 0;
63 delay_duration.tv_usec = milliseconds * 1000;
64 select(0, NULL, NULL, NULL, &delay_duration);
70 // c-file-style: "linux"