Please consider this code :
struct timeval start, end;
long mtime, seconds, useconds;
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
printf("Elapsed time: %ld milliseconds\n", mtime);
is the function which is being profiled.
The code was extracted from here :
If you need microsecond precision just use
If you're developing in kernel mode please consider using this function :
Hope it helps.