I am trying to do a timer in microseconds, but it's not quite working.
#include <time.h>
#include <iostream>
#include <unistd.h>
using namespace std;
int main ()
{
    struct timespec start_time;
    struct timespec end_time;
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
    usleep(5000);
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
    cout << "START: " << (start_time.tv_nsec/1000) << endl;
    cout << "END: " << (end_time.tv_nsec/1000) << endl;
    cout << "DIFF: " << (end_time.tv_nsec - start_time.tv_nsec) /1000 << endl;
    return 0;
}
The result look like this:
START: 3586
END: 3630
DIFF: 43
I need the DIFF be around 5000. Any suggestions?
 
     
     
    