22const double Stopwatch::NSEC = 1E-9;
46 clock_gettime(CLOCK_MONOTONIC, &time);
48 time = mach_absolute_time();
56 "WARNING: Unable to start clock, clock already running.\n");
109 time_t secLast = time.tv_sec;
110 long nsecLast = time.tv_nsec;
112 clock_gettime(CLOCK_MONOTONIC, &time);
113 return (
double)(time.tv_sec - secLast)
114 + (
double)(time.tv_nsec - nsecLast) *
NSEC;
116 uint64_t lastTime = time;
117 uint64_t time = mach_absolute_time();
118 static mach_timebase_info_data_t info = {0, 0};
120 if (info.denom == 0) mach_timebase_info(&info);
121 return ((time - lastTime) * (info.numer / info.denom)) *
NSEC;
127 "WARNING: Unable to update time, clock not running.\n");
double getTotal() const
Return total time elapsed (of a stopped watch).
void reset()
Reset stopwatch (total and loop time zero, clock not running).
double stop()
Stop and return total time.
void start(bool newLoop=true)
Start the stopwatch.
double getLoop() const
Return time elapsed in last loop interval (of a stopped watch).
double loop()
Stop and return loop time.