Skip to content

Commit 1a6be57

Browse files
bench: Make benchmarks compile on MSVC
1 parent 0e5cbd0 commit 1a6be57

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/bench.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,31 @@
77
#ifndef SECP256K1_BENCH_H
88
#define SECP256K1_BENCH_H
99

10+
#include <stdlib.h>
1011
#include <stdint.h>
1112
#include <stdio.h>
1213
#include <string.h>
13-
#include "sys/time.h"
14+
15+
#if (defined(_MSC_VER) && _MSC_VER >= 1900)
16+
# include <time.h>
17+
#else
18+
# include "sys/time.h"
19+
#endif
1420

1521
static int64_t gettime_i64(void) {
22+
#if (defined(_MSC_VER) && _MSC_VER >= 1900)
23+
/* C11 way to get wallclock time */
24+
struct timespec tv;
25+
if (!timespec_get(&tv, TIME_UTC)) {
26+
fputs("timespec_get failed!", stderr);
27+
exit(1);
28+
}
29+
return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL;
30+
#else
1631
struct timeval tv;
1732
gettimeofday(&tv, NULL);
1833
return (int64_t)tv.tv_usec + (int64_t)tv.tv_sec * 1000000LL;
34+
#endif
1935
}
2036

2137
#define FP_EXP (6)

0 commit comments

Comments
 (0)