struct timeval tempo1, tempo2;
long elapsed_utime; /* elapsed time in microseconds */
long elapsed_mtime; /* elapsed time in milliseconds */
long elapsed_seconds; /* diff between seconds counter */
long elapsed_useconds; /* diff between microseconds counter */
long total_usec = 0, total_msec = 0;
void StartSysTimer() {
gettimeofday(&tempo1, NULL);
}
void EndSysTimer() {
gettimeofday(&tempo2, NULL);
elapsed_seconds = tempo2.tv_sec - tempo1.tv_sec;
elapsed_useconds = tempo2.tv_usec - tempo1.tv_usec;
elapsed_utime = (elapsed_seconds) * 1000000 + elapsed_useconds;
elapsed_mtime = ((elapsed_seconds) * 1000 + elapsed_useconds/1000.0) + 0.5;
total_usec = total_usec + elapsed_utime;
total_msec = total_msec + elapsed_mtime;
}
void OutputTime() {
printf("Elapsed time = %ld microseconds\n", total_usec);
printf("Elapsed time = %ld milliseconds\n", total_msec);
}