文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>linux获得微秒时间操作

linux获得微秒时间操作

时间:2010-11-18  来源:xjh200858

#include <sys/time.h>
  #include <stdio.h>
  #include <math.h>
  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 */
   };
相关阅读 更多 +
排行榜 更多 +
幸运硬币官方正版下载

幸运硬币官方正版下载

休闲益智 下载
宝宝来找茬手机版 v9.86.00.00 安卓版

宝宝来找茬手机版 v9.86.00.00 安卓版

休闲益智 下载
翻滚飞机大战最新版 v1.0.4 安卓版

翻滚飞机大战最新版 v1.0.4 安卓版

飞行射击 下载