Chinaunix首页 | 论坛 | 博客
  • 博客访问: 87429
  • 博文数量: 23
  • 博客积分: 1431
  • 博客等级: 上尉
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-31 16:03
文章分类

全部博文(23)

文章存档

2011年(2)

2010年(11)

2009年(10)

我的朋友
最近访客

分类: LINUX

2010-11-18 16:56:35

#include
  #include
  #include
  void function()/*用来耗用一定的时间而已,无实际用处的函数*/
  {
   unsigned int i,j;
   double y;
   for(i=0;i<10000;i++)
   for(j=0;j<10000;j++)
   y=sin((double)i);
  }
  int main(int argc, char ** argv)
  {
   struct timeval tpstart,tpend;
   float timeuse;
   gettimeofday(&tpstart,NULL);
   function();
   gettimeofday(&tpend,NULL);
   timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
   timeuse/=1000000;
   printf("Used Time:%f\n",timeuse);
   exit(0);
  }
  主要是用到了gettimeofday函数,函数里用到了这个结构:
  
  struct timeval {
   long tv_sec; /* seconds */
   long tv_usec; /* microseconds */
   };
阅读(1868) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-19 15:19:03

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com