#include <stdio.h>
#include <sys/time.h>   /* For gettimeofday() */
#include <string.h>     /* For strerror() */
#include <errno.h>      /* For errno */


/*
** Call gettimeofday() and convert result into a double
** with usec resolution. Use it like this:
**
** double t1, t2;
**
**     t1= dclock();
**     What it is that you want to measure
**     t2= dclock();
**     printf("Time spent was %9.6f s\n", t2 - t1);
*/
double
dclock(void)
{

int rc;
struct timeval tv;
double result;


    rc= gettimeofday(&tv, (struct timezone *) 0);
    if (rc != 0)   {
        fprintf(stderr, "ERROR gettimeofday() failed: %s\n", strerror(errno));
        return 0.0;
    }

    /* result= tv.tv_sec * 1000000 + tv.tv_usec; */
    result= (double) tv.tv_usec;
    result= result / 1000000.0;
    result= result + (double) tv.tv_sec;
    return result;

}  /* end of dclock() */
