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