linux编程中,如果用到计时,可以用struct timeval获取系统时间。struct timeval的函数原型如下:
struct timeval { __kernel_time_t tv_sec; /* seconds */ __kernel_suseconds_t tv_usec; /* microseconds */ };
int main() { struct timeval tv; long long start_time, stop_time, delta_time; gettimeofday(&tv, NULL); start_time= tv.tv_usec; // your code here gettimeofday(&tv, NULL); stop_time = tv.tv_usec; delta_time = (stop_time - start_time + 1000000)%1000000; }
struct timeval 计时问题,布布扣,bubuko.com
原文:http://www.cnblogs.com/craftor/p/3811597.html