在软件设计中经常会用到关于时间的处理,用来计算语句、函数的执行时间,这时就需要精确到毫秒甚至是微妙的时间。int gettimeofday(struct timeval *tv, struct timezone *tz);int settimeofday(const struct timeval *tv , const struct timezone *tz);struct timeval { time_t tv_sec; /* seconds */ SUSEconds_t tv_usec; /* microseconds */}; struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ int tz_dsttime; /* type of DST correction */}; 下面是个简单的例子,用来统计程序的执行时间: …struct timeval t_start,t_end; long cost_time = 0; //get start timegettimeofday(&t_start, NULL);printf("Start time: %ld us", t_start.tv_usec); //some operation… //get end timegettimeofday(&t_end, NULL);printf("End time: %ld us", t_end.tv_usec); //calculate time slotcost_time = t_end.tv_usec - t_start.tv_usec;printf("Cost time: %ld us", cost_time);… 输出:Start time: 438061 usEnd time: 459867 usCost time: 21806 usLinux管道pipe使用实例Ubuntu 10.04下安装Qt环境及Qt Creator开发工具相关资讯 Linux教程
- Linux教程:如何在命令行中查看目 (07/28/2014 12:22:23)
- Linux 修改root密码 (11/03/2012 07:53:38)
- su - root 与su root的区别 (06/06/2012 00:39:40)
| - Linux进程间通信:消息队列 (01/28/2013 09:43:00)
- U盘安装Linux开机无法启动解决方法 (10/07/2012 08:55:52)
- Windows 7/Linux 同步时间 (05/15/2012 06:17:55)
|
本文评论 查看全部评论 (0)