MSVC: Provide an implementation of gettimeofday()

master
Adrian Perez de Castro 2019-08-05 16:57:45 +03:00 committed by Ran Benita
parent f1186acfd4
commit 9e3045c7f5
1 changed files with 31 additions and 1 deletions

View File

@ -26,9 +26,39 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <sys/time.h>
#include "bench.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 void
bench_start(struct bench *bench) bench_start(struct bench *bench)