gethrtime, gethrvtime - get high resolution time
The gethrtime() function returns the current high-resolution
real time. Time is expressed as nanoseconds since some arbi-
trary 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) or settimeofday(3C). The hi-
res timer is ideally suited to performance measurement
tasks, where cheap, accurate interval timing is required.
The gethrvtime() function returns the current high-
resolution LWP virtual time, expressed as total nanoseconds
of execution time. This function requires that micro state
accounting be enabled with the ptime utility (see proc(1)).
The gethrtime() and gethrvtime() functions both return an
hrtime_t, which is a 64-bit (long long) signed integer.
The following code fragment measures the average cost of
hrtime_t start, end;
int i, iters = 100;
start = gethrtime();
for (i = 0; i < iters; i++)
end = gethrtime();
printf("Avg getpid() time = %lld nsec\n", (end - start) / iters);
See attributes(5) for descriptions of the following attri-
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
| MT-Level | MT-Safe |
proc(1), adjtime(2), gettimeofday(3C), settimeofday(3C),
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 back-
ward, it won't periodically wrap) and linear (it won't occa-
sionally 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.
Man(1) output converted with