8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / man / man3c / gethrtime.3c
blob49bdae813da339ce1e6b9349284383e53aab019c
1 '\" te
2 .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH GETHRTIME 3C "Sep 7, 2004"
7 .SH NAME
8 gethrtime, gethrvtime \- get high resolution time
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/time.h>
14 \fBhrtime_t\fR \fBgethrtime\fR(\fBvoid\fR);
15 .fi
17 .LP
18 .nf
19 \fBhrtime_t\fR \fBgethrvtime\fR(\fBvoid\fR);
20 .fi
22 .SH DESCRIPTION
23 .sp
24 .LP
25 The \fBgethrtime()\fR function returns the current high-resolution real time.
26 Time is expressed as nanoseconds since some arbitrary time in the past; it is
27 not correlated in any way to the time of day, and thus is not subject to
28 resetting or drifting by way of \fBadjtime\fR(2) or \fBsettimeofday\fR(3C). The
29 hi-res timer is ideally suited to performance measurement tasks, where cheap,
30 accurate interval timing is required.
31 .sp
32 .LP
33 The \fBgethrvtime()\fR function returns the current high-resolution LWP virtual
34 time, expressed as total nanoseconds of execution time.
35 .sp
36 .LP
37 The \fBgethrtime()\fR and \fBgethrvtime()\fR functions both return an
38 \fBhrtime_t,\fR which is a 64-bit (\fBlong long\fR) signed integer.
39 .SH EXAMPLES
40 .sp
41 .LP
42 The following code fragment measures the average cost of \fBgetpid\fR(2):
43 .sp
44 .in +2
45 .nf
46 \fBhrtime_t start, end;
47 int i, iters = 100;
49 start = gethrtime();
50 for (i = 0; i < iters; i++)
51         getpid();
52 end = gethrtime();
54 printf("Avg getpid() time = %lld nsec\en", (end \(mi start) / iters);\fR
55 .fi
56 .in -2
58 .SH ATTRIBUTES
59 .sp
60 .LP
61 See \fBattributes\fR(5) for descriptions of the following attributes:
62 .sp
64 .sp
65 .TS
66 box;
67 c | c
68 l | l .
69 ATTRIBUTE TYPE  ATTRIBUTE VALUE
71 MT-Level        MT-Safe
72 .TE
74 .SH SEE ALSO
75 .sp
76 .LP
77 \fBproc\fR(1), \fBadjtime\fR(2), \fBgettimeofday\fR(3C),
78 \fBsettimeofday\fR(3C), \fBattributes\fR(5)
79 .SH NOTES
80 .sp
81 .LP
82 Although the units of hi-res time are always the same (nanoseconds), the actual
83 resolution is hardware dependent.  Hi-res time is guaranteed to be monotonic
84 (it won't go backward, it won't periodically wrap) and linear (it won't
85 occasionally speed up or slow down for adjustment, like the time of day can),
86 but not necessarily unique: two sufficiently proximate calls may return the
87 same value.