16 gettimeofday(¤t_time, 0);
20 int64_t Timer::get_difference(struct timeval *result)
22 gettimeofday(&new_time, 0);
24 result->tv_usec = new_time.tv_usec - current_time.tv_usec;
25 result->tv_sec = new_time.tv_sec - current_time.tv_sec;
26 if(result->tv_usec < 0)
28 result->tv_usec += 1000000;
32 return (int64_t)result->tv_sec * 1000 + (int64_t)result->tv_usec / 1000;
35 int64_t Timer::get_difference()
37 gettimeofday(&new_time, 0);
39 new_time.tv_usec -= current_time.tv_usec;
40 new_time.tv_sec -= current_time.tv_sec;
41 if(new_time.tv_usec < 0)
43 new_time.tv_usec += 1000000;
47 return (int64_t)new_time.tv_sec * 1000 +
48 (int64_t)new_time.tv_usec / 1000;
51 int64_t Timer::get_scaled_difference(long denominator)
53 get_difference(&new_time);
54 return (int64_t)new_time.tv_sec * denominator +
55 (int64_t)((double)new_time.tv_usec / 1000000 * denominator);
58 int Timer::delay(long milliseconds)
60 struct timeval delay_duration;
61 delay_duration.tv_sec = 0;
62 delay_duration.tv_usec = milliseconds * 1000;
63 select(0, NULL, NULL, NULL, &delay_duration);