2011年8月4日 星期四

How to calculate function time cost in C

#include <sys/time.h> 
#include <stdio.h> 

int main(){
 struct timeval tv1, tv2;
 gettimeofday(&tv1,NULL);

 usleep(1000);

 gettimeofday(&tv2,NULL);

 printf("Time Cost is %d ms\n", (tv1.tv_sec - tv2.tv_sec) * 1000 );
}

沒有留言:

張貼留言