gethrtime(3C)gethrtime(3C)NAME
gethrtime() - get high resolution time
SYNOPSIS DESCRIPTION
The function returns the current high-resolution real time. Time is expressed as nanoseconds since a certain time in the past. This API
uses a fast light weight system call to get the nanoseconds from a certain time. It is not correlated in any way to the time of day. This
API is used for performance measurement tasks and is used for cheap and accurate interval timing.
is a signed 64-bit number.
RETURN VALUE
Upon successful completion, returns a number of nanoseconds. Otherwise, a value of -1 is returned.
WARNINGS
This API will only be available if the application is being compiled in -Ae mode (extended ANSI) because 64-bit integer numbers are not
available in -Aa (ANSI) mode. Please refer to cc(1).
EXAMPLES
The following code fragment measures the average cost of
hrtime_t begin, end;
int i, count = 1000;
begin = gethrtime();
for (i = 0; i < count; i++)
getgid();
end = gethrtime();
printf("Avg getgid() time = %lld nsec", (end - begin)/count );
gethrtime(3C)
Check Out this Related Man Page
gethrtime(3C) Standard C Library Functions gethrtime(3C)NAME
gethrtime, gethrvtime - get high resolution time
SYNOPSIS
#include <sys/time.h>
hrtime_t gethrtime(void);
hrtime_t gethrvtime(void);
DESCRIPTION
The gethrtime() 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) or settime-
ofday(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.
The gethrtime() and gethrvtime() functions both return an hrtime_t, which is a 64-bit (long long) signed integer.
EXAMPLES
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
", (end - start) / iters);
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO proc(1), adjtime(2), gettimeofday(3C), settimeofday(3C), attributes(5)NOTES
Although the units of hi-res time are always the same (nanoseconds), the actual resolution is hardware dependent. Hi-res time is guaran-
teed 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 adjust-
ment, like the time of day can), but not necessarily unique: two sufficiently proximate calls may return the same value.
SunOS 5.11 7 Sep 2004 gethrtime(3C)
Hello to anyone who can help me!
I am in need of some help in procuring a more exact timing scheme in C for use with gcc.
I manage to get a timing in seconds just fine using difftime(). However, I need more accurate.. milliseconds... no clue.
Please help?
Brian (2 Replies)
i am using function
gethrtime() in sun solaries
to get the time independent of the system time.Problem with this function is if we restart the system time will change to '0'.is there any other way to resolve this problem.
thanks & regards
suresh (3 Replies)
Hello ,
i have read the manual page of alloca ,
it is documented there that "alloca works similar to the malloc but it allocates memory from stack and frees automatically".
i can't get how can i use that in a program .
if i'm not wrong can i use that like :
#include<stdio.h>... (24 Replies)
Hi,
I have a simulation program which creates two threads and I would like to know if I can measure the time of each individual thread. Threads communicate (I use pthread to manage them) and I want to measure communication time. I found a solution with clock_gettime and CLOCK_THREAD_CPUTIME_ID... (32 Replies)
Writing a Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX
I have over the years come across the same issue a couple of times, and it normally is that the read speed on SAN is absolutely atrocious when doing non-sequential I/O to the disks. Problem being of... (7 Replies)
HI
I have a Red Hat Enterprise with Real Time kernel.
Are you aware if there are C functions for this kernel or some code/library for this OS for measuring time more lightweight than clock_gettime and gettimeofday? THe hardware I have is NUMA.
Reading forums I found gethrtime but it is... (1 Reply)
Hi all,
I am working on a software, which was developed using C programming on unix environment. I have added certain functionality to the software.
Now, I interested in measuring time taken by new functionality (Mean value of huge amount of tests). Since new function will be part of many... (14 Replies)