'\" te .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. .TH gethrtime 3C "7 Sep 2004" "SunOS 5.11" "Standard C Library Functions" .SH NAME gethrtime, gethrvtime \- get high resolution time .SH SYNOPSIS .LP .nf #include \fBhrtime_t\fR \fBgethrtime\fR(\fBvoid\fR); .fi .LP .nf \fBhrtime_t\fR \fBgethrvtime\fR(\fBvoid\fR); .fi .SH DESCRIPTION .sp .LP The \fBgethrtime()\fR 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 \fBadjtime\fR(2) or \fBsettimeofday\fR(3C). The hi-res timer is ideally suited to performance measurement tasks, where cheap, accurate interval timing is required. .sp .LP The \fBgethrvtime()\fR function returns the current high-resolution LWP virtual time, expressed as total nanoseconds of execution time. .sp .LP The \fBgethrtime()\fR and \fBgethrvtime()\fR functions both return an \fBhrtime_t,\fR which is a 64-bit (\fBlong long\fR) signed integer. .SH EXAMPLES .sp .LP The following code fragment measures the average cost of \fBgetpid\fR(2): .sp .in +2 .nf 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\en", (end \(mi start) / iters); .fi .in -2 .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ MT-LevelMT-Safe .TE .SH SEE ALSO .sp .LP \fBproc\fR(1), \fBadjtime\fR(2), \fBgettimeofday\fR(3C), \fBsettimeofday\fR(3C), \fBattributes\fR(5) .SH NOTES .sp .LP 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.