Ubuntu工具

Linux系统计时器(LANG: C/C++)

GentleH posted @ 2013年11月28日 00:28 in Linux , 1299 阅读

Linux下的系统计时器很强大,计时精确。

#include <sys/time.h>

int main()
{
    timeval start,end;

    gettimeofday(&start,0);

    doSomething();

    gettimeofday(&end,0);

    double timeUse = 1000000*(end.tv_sec-start.tv_sec)+end.tv_usec-start.tv_usec;
    timeUse /= 1000; //计算秒则除以1000000
    
    printf("Use time: %lfms\n",timeUse);
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter