linux c 時間函數,獲取程序執行時間

#include <sys/time.h> 

void ctimeTest()
{
int i=1000;
timeval tvs,tve,tvlast;
gettimeofday(&tvs,NULL);
while (--i)
{
system("cd");
}
gettimeofday(&tve,NULL);
long span = (tve.tv_sec-tvs.tv_sec) * 1000000 + (tve.tv_usec-tvs.tv_usec);
char temp[1024];
sprintf(temp,"use time: %d microsecond (1s = 1000000microsecond)",span);
printf(temp);
}


更多時間函數請參考:

http://www.ej38.com/showinfo/linux-203376.html

http://blog.csdn.net/onezeros/article/details/4559891


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章