4 #ifndef TIMER_H_INCLUDED
5 #define TIMER_H_INCLUDED
7 #include <boost/predef.h>
11 #define NOMINMAX // otherwise std::max and std::min is defined
27 typedef std::chrono::system_clock clock_t;
36 return clock_t::now();
44 std::chrono::duration<double, std::nano> dur =
tic() - t0;
45 return dur.count() / 1e9;
55 typedef double time_point_t;
59 static time_point_t tic()
65 if (GetProcessTimes(GetCurrentProcess(),
66 &createTime, &exitTime, &kernelTime, &userTime) == -1)
67 throw std::runtime_error(
"Could not get CPU time point");
69 SYSTEMTIME userSystemTime;
70 if (FileTimeToSystemTime(&userTime, &userSystemTime) == -1)
71 throw std::runtime_error(
"Could not get CPU time point");
73 return (
double)userSystemTime.wHour * 3600.0 +
74 (double)userSystemTime.wMinute * 60.0 +
75 (
double)userSystemTime.wSecond +
76 (double)userSystemTime.wMilliseconds / 1000.0;
82 static double toc(time_point_t
const &t0)
89 typedef clock_t time_point_t;
91 static time_point_t tic()
96 static double toc(time_point_t
const &t0)
98 return double(tic() - t0) / CLOCKS_PER_SEC;