#include "Timer.h" extern struct timeval start; double Timer::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) */ Timer::Timer() { Reset(); }; Timer::~Timer() {} void Timer::Reset() { /* this sets the timer back to zero and returns 0 on success, -1 on failure */ int failurep; failurep=gettimeofday(&start,NULL); if (failurep) { printf ("Reset failed\n"); } }; /* Reset() */ double Timer::Check() { /* this returns the time elapsed since Reset() was called if gettimeofday fails, -1 is returned */ struct timeval now; if (gettimeofday(&now,NULL)) printf("Check failed\n"); return(timediff(start,now)); }; /* Check() */