13 #ifndef __STOUT_STOPWATCH_HPP__ 14 #define __STOUT_STOPWATCH_HPP__ 20 #include <mach/clock.h> 21 #include <mach/mach.h> 71 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
72 clock_get_time(cclock, &mts);
73 mach_port_deallocate(mach_task_self(), cclock);
74 ts.tv_sec = mts.tv_sec;
75 ts.tv_nsec = mts.tv_nsec;
77 const static __int64 ticks_in_second = 10000000i64;
78 const static __int64 ns_in_tick = 100;
83 sizeof(FILETIME) ==
sizeof(__int64),
84 "stopwatch: We currently require `FILETIME` to be 64 bits in size");
85 __int64 filetime_in_ticks;
87 GetSystemTimeAsFileTime(reinterpret_cast<FILETIME*>(&filetime_in_ticks));
91 ts.tv_sec = filetime_in_ticks / ticks_in_second;
92 ts.tv_nsec = filetime_in_ticks % ticks_in_second * ns_in_tick;
94 clock_gettime(CLOCK_REALTIME, &ts);
99 static uint64_t diff(
const timespec& from,
const timespec& to)
101 return ((from.tv_sec - to.tv_sec) * 1000000000LL)
102 + (from.tv_nsec - to.tv_nsec);
106 timespec started, stopped;
109 #endif // __STOUT_STOPWATCH_HPP__ Definition: stopwatch.hpp:30
void stop()
Definition: stopwatch.hpp:48
Nanoseconds elapsed() const
Definition: stopwatch.hpp:54
Stopwatch()
Definition: stopwatch.hpp:33
void start()
Definition: stopwatch.hpp:42
Definition: duration.hpp:165