Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

gethrtime(3c) [hpux man page]

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)
Man Page

8 More Discussions You Might Find Interesting

1. Programming

time functions help?

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)
Discussion started by: bcowan
2 Replies

2. HP-UX

Oracle 9i install: Error in invoking target install of makefile

I receive an error while installing Oracle 9i: Error in invoking target install of makefile /opt/oracle/product/9.2.0/sqlplus/lib/ins_sqlplus.mk Furthermore: $ whoami oracle $ echo $ORACLE_HOME /opt/oracle/product/9.2.0 $ pwd /opt/oracle/product/9.2.0/sqlplus/lib $ ll total... (5 Replies)
Discussion started by: chris2005
5 Replies

3. Solaris

getting time independent of system time in solaries

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)
Discussion started by: suresh_rtp
3 Replies

4. Programming

Use of alloca function

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)
Discussion started by: MrUser
24 Replies

5. Shell Programming and Scripting

Measure thread execution (in C, unix)

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)
Discussion started by: Tinkh
32 Replies

6. Programming

Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX

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)
Discussion started by: vrghost
7 Replies

7. Red Hat

lightweight function for measuring time ( better than clock_getime )

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)
Discussion started by: manustone
1 Replies

8. Programming

Efficient logging of time measurements

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)
Discussion started by: tamil.pamaran
14 Replies