GETHRTIME(3C) Standard C Library Functions GETHRTIME(3C)
gethrtime, gethrvtime - get high resolution time
#include <sys/time.h> hrtime_t gethrtime
); hrtime_t gethrvtime
function returns the current high-resolution real time.
Time is expressed as nanoseconds since some arbitrary time in the past;
it is not correlated in any way to the time of day, and thus is not
subject to resetting or drifting by way of adjtime(2)
. The hi-res timer is ideally suited to performance
measurement tasks, where cheap, accurate interval timing is required.
function returns the current high-resolution LWP virtual
time, expressed as total nanoseconds of execution time.
functions both return an hrtime_t,
is a 64-bit (long long
) signed integer.
The following code fragment measures the average cost of getpid(2)
: hrtime_t start, end; int i, iters = 100; start = gethrtime(); for (i = 0; i < iters; i++) getpid(); end = gethrtime(); printf("Avg getpid() time = %lld nsec\n", (end - start) / iters);
for descriptions of the following attributes:
|ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|MT-Level | MT-Safe |
SEE ALSO proc(1)
Although the units of hi-res time are always the same (nanoseconds), the
actual resolution is hardware dependent. Hi-res time is guaranteed to be
monotonic (it won't go backward, it won't periodically wrap) and linear
(it won't occasionally speed up or slow down for adjustment, like the
time of day can), but not necessarily unique: two sufficiently proximate
calls may return the same value.
September 7, 2004 GETHRTIME(3C)