Skip to content

Commit 8a3b9d3

Browse files
committed
refactor: move 'gettime_i64()' to testutil.h
Relocate the clock time getter to testutil.h to make it easily reusable across tests. This will be useful for the upcoming unit test framework.
1 parent 03fb60a commit 8a3b9d3

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/bench.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,7 @@
1212
#include <stdio.h>
1313
#include <string.h>
1414

15-
#if (defined(_MSC_VER) && _MSC_VER >= 1900)
16-
# include <time.h>
17-
#else
18-
# include <sys/time.h>
19-
#endif
20-
21-
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(EXIT_FAILURE);
28-
}
29-
return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL;
30-
#else
31-
struct timeval tv;
32-
gettimeofday(&tv, NULL);
33-
return (int64_t)tv.tv_usec + (int64_t)tv.tv_sec * 1000000LL;
34-
#endif
35-
}
15+
#include "util.h"
3616

3717
#define FP_EXP (6)
3818
#define FP_MULT (1000000LL)

src/util.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ static void print_buf_plain(const unsigned char *buf, size_t len) {
4545
printf("\n}\n");
4646
}
4747

48+
#if (defined(_MSC_VER) && _MSC_VER >= 1900)
49+
# include <time.h>
50+
#else
51+
# include <sys/time.h>
52+
#endif
53+
54+
static int64_t gettime_i64(void) {
55+
#if (defined(_MSC_VER) && _MSC_VER >= 1900)
56+
/* C11 way to get wallclock time */
57+
struct timespec tv;
58+
if (!timespec_get(&tv, TIME_UTC)) {
59+
fputs("timespec_get failed!", stderr);
60+
exit(EXIT_FAILURE);
61+
}
62+
return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL;
63+
#else
64+
struct timeval tv;
65+
gettimeofday(&tv, NULL);
66+
return (int64_t)tv.tv_usec + (int64_t)tv.tv_sec * 1000000LL;
67+
#endif
68+
}
69+
4870
# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
4971
# if SECP256K1_GNUC_PREREQ(2,7)
5072
# define SECP256K1_INLINE __inline__

0 commit comments

Comments
 (0)