These two bits of code can be used to record & output the execution time of a piece of code in microseconds. NOTE: The functions used here are only available on BSD-like systems (I think).
1
2 /* Put this line at the top of the file: */
3
4
5 /* Put this right before the code you want to time: */
6 struct timeval timer_start, timer_end;
7 gettimeofday(&timer_start, NULL);
8
9 /* Put this right after the code you want to time: */
10 gettimeofday(&timer_end, NULL);
11 double timer_spent = timer_end.tv_sec - timer_start.tv_sec + (timer_end.tv_usec - timer_start.tv_usec) / 1000000.0;
12 printf("Time spent: %.6f\n", timer_spent);