/* timer structure */ typedef struct { struct timeval s; struct timeval e; } TIMER, *TIMERPTR; /* Start the timer */ void startTimer(TIMERPTR tp) { gettimeofday(&tp->s,NULL); } /* Return the time since the timer was started in microseconds */ unsigned long getTime(TIMERPTR tp) { gettimeofday(&tp->e,NULL); return ((tp->e.tv_sec*((unsigned long)1000000)+tp->e.tv_usec) - (tp->s.tv_sec*((unsigned long)1000000)+tp->s.tv_usec)); } /* To use this code do the following: TIMERPTR myTimer; unsigned long runtime; myTimer=(TIMERPTR)malloc(sizeof(TIMER)); startTimer(myTimer); // do the work you want to time runtime=getTime(myTimer); printf("Run time was %ld.\n",runtime); */