1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <time.h>
#include <sys/time.h>
#ifdef LINUX
#include <unistd.h>
#endif
double GetClock ( void )
{
double d ;
#ifndef LINUX
#ifdef WINDOWS
struct timeval tval ;
struct timezone *tz=(struct timezone *)NULL ;
timerclear(&tval);
if ( gettimeofday(&tval, tz) )
{
#ifdef DEBUG
fprintf (stderr, " CLOCK ERROR !!!");
#endif
}
d = ((double)(tval.tv_usec)/1000000.0) ;
d = (double) tval.tv_sec + d ;
#else
struct timespec cur_time, res ;
if (clock_gettime(CLOCK_REALTIME, &cur_time))
{
#ifdef DEBUG
fprintf (stderr, " CLOCK ERROR !!!");
#endif
}
d = ((double)(cur_time.tv_nsec)/1000.0) / 1000000.0 ;
d = (double) cur_time.tv_sec + d ;
#endif
#else
struct timeval tval ;
struct timezone *tz=(struct timezone *)NULL ;
timerclear(&tval);
if ( gettimeofday(&tval, tz) )
{
#ifdef DEBUG
fprintf (stderr, " CLOCK ERROR !!!");
#endif
}
d = ((double)(tval.tv_usec)/1000000.0) ;
d = (double) tval.tv_sec + d ;
#endif
return d ;
} |
Partager