/* determine minimum granularity of gettimeofday */
/* 21/Jun/2001 brg */
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>

/* int gettimeofday(struct timeval *tv, struct timezone *tz); */

double timediff(struct timeval a, struct timeval b)
{
	double a_d = a.tv_sec + (((double)a.tv_usec) / 1000000.0);
	double b_d = b.tv_sec + (((double)b.tv_usec) / 1000000.0);
	return a_d - b_d;
}

int main(int argc, char **argv)
{
	struct timeval last;
	struct timeval next;
	double diff=1.0, mindiff=1.0;
	int ctr;
	gettimeofday(&last, NULL);
	do {
		ctr=0;
		do {
			gettimeofday(&next, NULL);
			ctr++;
		} while ((next.tv_usec == last.tv_usec) && (next.tv_sec == last.tv_sec));
		diff = timediff(next, last);
		if (diff< mindiff) { mindiff = diff;
		printf("%.6f %d\n", mindiff, ctr); }
	} while (1);
}


