#include "Timer.h" static struct timeval start; void ResetTimer() { /* this sets the timer back to zero and returns 0 on success, -1 on failure */ int failurep; failurep=gettimeofday(&start,NULL); if (failurep) { printf ("ResetTimer failed\n"); } } /* ResetTimer() */ double timediff(struct timeval time1, struct timeval time2) { /* this function returns the difference between 2 struct timevals. time2 should be the later time */ double result; result = time2.tv_sec-time1.tv_sec; result += (double)(time2.tv_usec-time1.tv_usec)/1000000; return(result); } /* timediff(time1,time2) */ double CheckTimer() { /* this returns the time elapsed since ResetTimer() was called if gettimeofday fails, -1 is returned */ struct timeval now; if (gettimeofday(&now,NULL)) printf("CheckTimer failed\n"); return(timediff(start,now)); } /* CheckTimer() */