1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
// Start of timing.h.
// The function get_wall_time() returns the wall time in microseconds
// (with an unspecified offset).
#ifdef _WIN32
#include <windows.h>
static int64_t get_wall_time(void) {
LARGE_INTEGER time,freq;
assert(QueryPerformanceFrequency(&freq));
assert(QueryPerformanceCounter(&time));
return ((double)time.QuadPart / freq.QuadPart) * 1000000;
}
static int64_t get_wall_time_ns(void) {
return get_wall_time() * 1000;
}
#else
// Assuming POSIX
#include <time.h>
#include <sys/time.h>
static int64_t get_wall_time_ns(void) {
struct timespec time;
assert(clock_gettime(CLOCK_MONOTONIC, &time) == 0);
return time.tv_sec * 1000000000 + time.tv_nsec;
}
static int64_t get_wall_time(void) {
return get_wall_time_ns() / 1000;
}
#endif
// End of timing.h.
|