summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorAdrian Perez de Castro <aperez@igalia.com>2019-08-05 16:57:45 +0300
committerRan Benita <ran234@gmail.com>2019-12-28 16:12:15 +0200
commit9e3045c7f50a4666b9938366aec7cb9a938794e9 (patch)
treeeaf145edaa52c0697367f1b4d9029bf6425444e2 /bench
parentf1186acfd43b2da98f09e40e9aecf164ac17d9a5 (diff)
downloadxorg-lib-libxkbcommon-9e3045c7f50a4666b9938366aec7cb9a938794e9.tar.gz
MSVC: Provide an implementation of gettimeofday()
Diffstat (limited to 'bench')
-rw-r--r--bench/bench.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/bench/bench.c b/bench/bench.c
index 2c5f23d..c28ac65 100644
--- a/bench/bench.c
+++ b/bench/bench.c
@@ -26,9 +26,39 @@
#include <assert.h>
#include <stdio.h>
-#include <sys/time.h>
#include "bench.h"
+#include "../src/utils.h"
+
+#ifndef _MSC_VER
+#include <sys/time.h>
+#else
+#include <windows.h>
+#include <stdint.h>
+
+struct timeval {
+ long tv_sec, tv_usec;
+};
+
+static int
+gettimeofday(struct timeval *tv, void *unused)
+{
+ static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
+
+ SYSTEMTIME system_time;
+ FILETIME file_time;
+ uint64_t t;
+
+ GetSystemTime(&system_time);
+ SystemTimeToFileTime(&system_time, &file_time);
+ t = (uint64_t) file_time.dwLowDateTime;
+ t += ((uint64_t) file_time.dwHighDateTime) << 32;
+
+ tv->tv_sec = (long) ((t - EPOCH) / 10000000L);
+ tv->tv_usec = (long) (system_time.wMilliseconds * 1000);
+ return 0;
+}
+#endif
void
bench_start(struct bench *bench)