微秒级计时 gettimeofday

首先介绍几种秒:(我居然之前总是认为microsecond是毫秒,囧!)

millisecond----毫秒

microsecond---微秒

nanosecond---纳秒

1 second = 10e3 milisecond = 10e6 microsecond = 10e9 nanosecond

 

 

直接上man手册,英文的,你懂的...

 

NAME

gettimeofday - get the date and time

SYNOPSIS

#include <sys/time.h> tp, void *restrict tzp);

int gettimeofday(struct timeval *restrict

DESCRIPTION

The gettimeofday() function shall obtain the current time, expressed as seconds and microseconds since the Epoch, and store it in the timeval structure pointed to by tp. The resolution of the system clock is unspecified.

If tzp is not a null pointer, the behavior is unspecified.

RETURN VALUE

The gettimeofday() function shall return 0 and no value shall be reserved to indicate an error.

 

另外,timeval的定义:

struct timeval {
    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* microseconds */
};

对于时区tzp应该是NULL。

posted on 2010-12-14 21:53  Weifeng Wang  阅读(838)  评论(0编辑  收藏  举报

导航