我正在尝试以微秒为单位测量C时间。我尝试了这段代码,但值time_passed
是一个很大的数字,而不是0(或1)。
struct timeval start;
settimeofday(&start,NULL);
struct timeval stop;
settimeofday(&stop,NULL);
unsigned long long int time_passed =
(stop.tv_sec-start.tv_sec)*1000000 + (stop.tv_usec - start.tv_usec);
printf("time passed: %llu us\n",time_passed);
答案 0 :(得分:7)
当您应该致电settimeofday()
时,您正在呼叫gettimeofday()
!