易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux获取毫秒级时间


Linux获取毫秒级时间
Moakap
在软件设计中经常会用到关于时间的处理,用来计算语句、函数的执行时间,这时就需要精确到毫秒甚至是微妙的时间。
 
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
time
gettimeofday(&t_start,
NULL);
printf("Start
time: %ld us", t_start.tv_usec);
 
//some
operation

 
//get end time
gettimeofday(&t_end,
NULL);
printf("End
time: %ld us", t_end.tv_usec);
 
//calculate
time slot
cost_time =
t_end.tv_usec - t_start.tv_usec;
printf("Cost
time: %ld us", cost_time);

 
输出:
Start time:
438061 us
End time:
459867 us
Cost time:
21806 us


相关文档:

Linux新手要了解的十个知识点

Linux新手要了解的十个知识点
  1.Linux是大小写敏感的系统,举个例子,Mozilla, MOZILLA, mOzilla和 mozilla是四个不同的命令(但是只有第四个mozilla是真正有效的命令)。还有,my_filE, my_file,和 my_FILE是三个不同的文件。用户的登录名和秘密也是大小写敏感的(这是因为UNIX系统和C语言的传统一向是大小写敏感所致 ......

Linux命令:lsmod 显示已载入系统的模块

lsmod(list modules)
 
功能说明:显示已载入系统的模块。
语  法:lsmod
补充说明:执行lsmod指令,会列出所有已载入系统的模块。Linux操作系统的核心具有模块化的特性,应此在编译核心时,务须把全部的功能都放入核心。您可以将这些功能编译成一个个单独的模块,待需要时再分别载入。
范例:
[root@lin ......

在CentOS 5 或Red Hat Enterprise Linux安装语言包


Q. How do I install Languages in Linux after installation? I don’t have any language specific support installed but need to install the same. I’m using both RHEL 5 and CentOS 5.
A. Yellow dog Updater, Modified, a package manager for RPM-compatible Linux systems such as Cento ......

linux下创建oracle用户表空间

 就是在已有的数据库实例上创建一个新的帐号,访问一些新的表
 操作步骤如下:
 1、登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切换成oracle用户)
 2、以sysdba方式来打开sqlplus,命令如下: sqlplus "/as sysdba"
 3、查看我们常规将用户表空间放置位置 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号