计算时间相关

来源:互联网 发布:中国人眼睛的颜色 知乎 编辑:程序博客网 时间:2024/05/13 20:57

structtimespec{

__time_ttv_sec;  /*seconds 秒*/

longint tv_nsec; /*nanoseconds 纳秒*/

}

与struct timeval 不同,将结构体内成员微秒变换成纳秒

 <sys/time.h>:

  struct timeval {

  time_t tv_sec; /* seconds */

  suseconds_t tv_usec; /* microseconds */

};

(1) struct--timeval

--------------------------------------------------

struct timeval {

   time_t      tv_sec;     /* seconds */

   suseconds_t tv_usec;    /*microseconds */

};

millisecond        毫秒

microsecond        微秒

 

timeval表示一个时间点,比如:

timeval.tv_sec = 1   (s)

timevat.tv_usec = 500 000 (μs)

1:500 = 1s500000μs = 1.5s

 

(2) gettimeofday()

--------------------------------------------------

int gettimeofday(struct timeval *tv, structtimezone *tz);

 

   The functions gettimeofday() and settimeofday() can get and set the timeas well as a timezone.

   The use of the timezone structure is obsolete; the tz argument shouldnormally be specified as NULL.

 

(3) 运行结果:

--------------------------------------------------

time 1181788367:991487

time 1181788369:991602

 

http://www.ibm.com/developerworks/cn/views/linux/libraryview.jsp?sort_by=&show_abstract=true&show_all=&search_flag=&contentarea_by=Linux&search_by=%E8%BF%9B%E7%A8%8B%E9%97%B4%E9%80%9A%E4%BF%A1&topic_by=-1&type_by=%E6%89%80%E6%9C%89%E7%B1%BB%E5%88%AB&ibm-search=%E6%90%9C%E7%B4%A2

 

http://www.cnblogs.com/zhiranok/archive/2011/12/22/linux_IPC_latency.html
原创粉丝点击