Time of Day
There's nothing fancy here, just some comments on getting the time with reasonable resolution. Fancier techniques are required to go lower than microsecond resolution, many of which are not available on older Linux kernels.
/*----------------------------------------------------------------------
* show.c --- How to fetch time splits at microseconds resolution.
* Authors: Joe Kopena, November 2007
----------------------------------------------------------------------*/
#include <stdio.h>
#include <sys/time.h>
int main(int argc, char *argv[]) {
struct timeval currentTime;
// Use gettimeofday() to fetch time since epoch at microseconds
// resolution. Nanoseconds resolution unlikely to be supported on
// PDAs, so don't bother.
gettimeofday(¤tTime, NULL);
// Convert to double in case that's useful. Note that this may be
// costly on PDAs, which may not have floating point support, etc.
double currTime = currentTime.tv_sec +
((double) currentTime.tv_usec / (double) 1000000);
printf("%f [%d.%06d]\n",
currTime, // Seconds since epoch in double format
currentTime.tv_sec, // Seconds component of time since epoch
currentTime.tv_usec); // Microseconds component of time since epoch
// end main
}