I used something like this in one of my projects:
#include <sys/time.h>struct timeval start, end;gettimeofday(&start, NULL);//Computegettimeofday(&end, NULL);double elapsed = ((end.tv_sec - start.tv_sec) * 1000) + (end.tv_usec / 1000 - start.tv_usec / 1000);
This is for milliseconds and it works both for C and C++.