5 #ifndef SPICAR_STOPWATCH_H 6 #define SPICAR_STOPWATCH_H 12 #include <mach/clock.h> 13 #include <mach/mach.h> 22 #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time 25 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
26 clock_get_time(cclock, &mts);
27 mach_port_deallocate(mach_task_self(), cclock);
28 ts.tv_sec = mts.tv_sec;
29 ts.tv_nsec = mts.tv_nsec;
32 if(clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
35 return (
double) (ts.tv_sec*1000.0 + 1e-6*ts.tv_nsec);
44 void start() {startTics = getticks();}
45 double getTime() {elapsedms = (getticks() - startTics);
return elapsedms;}
48 #endif //SPICAR_STOPWATCH_H