您的位置:首页 > 运维架构 > Linux

linux c 时间函数,获取程序执行时间

2013-05-06 19:58 435 查看
#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

/article/7911000.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: