3 StopWatch::StopWatch() :
8 void StopWatch::start(void)
11 clock_gettime(CLOCK_MONOTONIC, &starttime);
14 long StopWatch::elapsedmsec(void)
16 if(!started) return -1;
19 clock_gettime(CLOCK_MONOTONIC, &tmp);
20 tmp = timedifference(starttime,tmp);
21 return tmp.tv_sec*1000+tmp.tv_nsec/1000000;
24 float StopWatch::elapsedsec(void)
26 if(!started) return -1;
29 clock_gettime(CLOCK_MONOTONIC, &tmp);
30 tmp = timedifference(starttime,tmp);
31 return tmp.tv_sec + (float)tmp.tv_nsec/1000000000;
34 timespec StopWatch::timedifference(timespec start, timespec end)
37 if ((end.tv_nsec-start.tv_nsec)<0) {
38 temp.tv_sec = end.tv_sec-start.tv_sec-1;
39 temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
41 temp.tv_sec = end.tv_sec-start.tv_sec;
42 temp.tv_nsec = end.tv_nsec-start.tv_nsec;