阅读内容

Linux计算时间间隔

[日期:2008-08-05] 来源:Linux公社  作者:Linux编辑


Linux计算时间间隔:
 
#include
#include

/*
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);


strut timeval {
long tv_sec; /* 秒数 */
long tv_usec; /* 微秒数 */
};
*/

struct timeval start,end;
int timeuse;

void time()
{
gettimeofday( &end, NULL );
timeuse = 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec - start.tv_usec;
timeuse /= 1000000;
printf("time used: %ds\n", timeuse);
}

void foo()
{
int i=0;
for(;i<10000;i++);
}

int main()
{
gettimeofday( &start, NULL );
foo();
time();
return 0;
}




相关资讯       linux编程 
本文评论       全部评论
发表评论
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款


点评: 字数
姓名:

L
I
N
U
X


GOOGLE搜索
Google