Use gettimeofday(), it measures time in microseconds. This code is just an example. Put the code you are trying to time between the two calls to gettimeofday(). Use timersub() to get the difference.
Code: Select all
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
int main(void)
{
struct timeval start;
struct timeval end;
struct timeval total;
gettimeofday(&start, NULL);
sleep(3);
gettimeofday(&end, NULL);
timersub(&end, &start, &total);
printf("time taken: %d.%06d\n", total.tv_sec, total.tv_usec);
return 0;
}
The call to sleep(3) is just an example to give something to time.