![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to print largest and smallest number. | amp10388 | UNIX for Dummies Questions & Answers | 2 | 05-07-2008 10:28 AM |
| checking the smallest and largest number | subin_bala | Shell Programming and Scripting | 4 | 04-24-2008 07:32 AM |
| DNS name resolution | e250user | SUN Solaris | 1 | 07-25-2006 11:13 AM |
| TCP/IP name resolution | progressdll | UNIX for Advanced & Expert Users | 2 | 05-07-2002 11:33 AM |
| Resolution..?? | Linux_fan | UNIX Desktop for Dummies Questions & Answers | 3 | 03-06-2002 11:33 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
The smallest resolution for gettimeofday would be microseconds according to the manpage.
|
|
||||
|
gettimeofday will give you the current date and time specified in seconds or microseconds from the UNIX Epoch but not the resolution of the system-wide clock so be specific as to what you want?
|
|
||||
|
Get clock resolutoin
/*
* Print the gettimeofday() clock resolution for this machine. * * Code taken from Iozone. Iozone Filesystem Benchmark * Author: Don Capps * */ #include <sys/time.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #define THISVERSION " Version $Revision: 1.2 $" double time_res,delay; void get_resolution(); /* Works with most compilers */ static double time_so_far1(); /* Works with most compilers */ /* * Measure and print the gettimeofday() resolution. */ main() { printf("\n\nMeasuring the gettimeofday() resolution\n\n"); get_resolution(); printf("Time resolution of gettimeofday() = %f seconds\n",time_res); printf("Time resolution of gettimeofday() = %f milli seconds\n", time_res*1000); printf("Time resolution of gettimeofday() = %f micro seconds\n\n", time_res*(1000*1000)); printf("Provided, courtesy of Iozone. http://www.iozone.org\n\n"); } /* * Lifted code from Iozone. */ #ifdef HAVE_ANSIC_C void get_resolution(void) #else void get_resolution() #endif { double starttime, finishtime; long j; again: finishtime=time_so_far1(); /* Warm up the instruction cache */ starttime=time_so_far1(); /* Warm up the instruction cache */ delay=j=0; /* Warm up the data cache */ while(1) { starttime=time_so_far1(); for(j=0;j< delay;j++) ; finishtime=time_so_far1(); if(starttime==finishtime) delay++; else break; } time_res = (finishtime-starttime)/1000000.0; } /* * Lifted code from Iozone. */ /************************************************************************/ /* Time measurement routines. */ /* Return time in microseconds */ /************************************************************************/ #ifdef HAVE_ANSIC_C static double time_so_far1(void) #else static double time_so_far1() #endif { /* For Windows the time_of_day() is useless. It increments in 55 milli second */ /* increments. By using the Win32api one can get access to the high performance */ /* measurement interfaces. With this one can get back into the 8 to 9 */ /* microsecond resolution. */ #ifdef Windows LARGE_INTEGER freq,counter; double wintime; double bigcounter; QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&counter); bigcounter=(double)counter.HighPart *(double)0xffffffff + (double)counter.LowPart; wintime = (double)(bigcounter/(double)freq.LowPart); return((double)wintime*1000000.0); #else #if defined (OSFV4) || defined(OSFV3) || defined(OSFV5) struct timespec gp; if (getclock(TIMEOFDAY, (struct timespec *) &gp) == -1) perror("getclock"); return (( (double) (gp.tv_sec)*1000000.0) + ( ((float)(gp.tv_nsec)) * 0.001 )); #else struct timeval tp; if (gettimeofday(&tp, (struct timezone *) NULL) == -1) perror("gettimeofday"); return ((double) (tp.tv_sec)*1000000.0) + (((double) tp.tv_usec) ); #endif #endif } |
| Sponsored Links | ||
|
|