18 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && \
22 #elif defined(__unix__) || defined(__unix) || \
23 (defined(__APPLE__) && defined(__MACH__))
26 #error "Unknown compiler"
107 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && \
110 LARGE_INTEGER time, freq;
111 if (!QueryPerformanceFrequency(&freq))
113 std::runtime_error(
"Cannot obtain system's time frequency.");
117 if (!QueryPerformanceCounter(&time))
119 std::runtime_error(
"Cannot obtain elapsed time.");
123 return static_cast<double>(time.QuadPart) / \
124 static_cast<double>(freq.QuadPart);
126 #elif defined(__unix__) || defined(__unix) || \
127 (defined(__APPLE__) && defined(__MACH__))
130 if (gettimeofday(&time, NULL))
132 std::runtime_error(
"Cannot obtain elapsed time.");
136 return static_cast<double>(time.tv_sec) + \
137 static_cast<double>(time.tv_usec) * 1e-6;
140 #error "Unknown compiler"
~Timer()
Destructor for Timer.
void start()
Starts the timer.
static double get_wall_time()
Returns the wall time since the epoch.
Timer()
constructor for Timer
void stop()
Stops the timer.
double elapsed() const
Returns the elapsed time in seconds.