/*
* san2(at)linuxchannel.net
*/
#include <stdio.h>
#include <sys/time.h>
double microtime(void);
#define NUL '\0'
#define MICRO_IN_SEC 1000000.00
#define SEC_IN_MIN 60
int main()
{
double s, e;
s = microtime();
e = microtime();
printf("%.8f\n",s);
printf("%.8f\n",e);
printf("%.8f\n",(e-s));
return;
}
double microtime(void)
{
struct timeval tp;
long sec = 0L;
double msec = 0.0;
double tsec = 0.0;
if (gettimeofday((struct timeval *) &tp, (NUL)) == 0)
{
msec = (double) (tp.tv_usec / MICRO_IN_SEC);
sec = tp.tv_sec;
if (msec >= 1.0) msec -= (long) msec;
tsec = msec + sec;
}
return tsec;
}
|