Skip to content

Commit f801054

Browse files
committed
tests: use timemono not time_now() for duration measurement.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 1df8613 commit f801054

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

bitcoin/test/run-secret_eq_consttime.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static struct timerel const_time_test(struct secret *s1,
1616
struct secret *s2,
1717
size_t off)
1818
{
19-
struct timeabs start, end;
19+
struct timemono start, end;
2020
int result = 0;
2121

2222
memset(s1, 0, RUNS * sizeof(*s1));
@@ -25,16 +25,16 @@ static struct timerel const_time_test(struct secret *s1,
2525
for (size_t i = 0; i < RUNS; i++)
2626
s2[i].data[off] = i;
2727

28-
start = time_now();
28+
start = time_mono();
2929
for (size_t i = 0; i < RUNS; i++)
3030
result += secret_eq_consttime(&s1[i], &s2[i]);
31-
end = time_now();
31+
end = time_mono();
3232

3333
if (result != RUNS / 256)
3434
errx(1, "Expected %u successes at offset %zu, not %u!",
3535
RUNS / 256, off, result);
3636

37-
return time_between(end, start);
37+
return timemono_between(end, start);
3838
}
3939

4040
static inline bool secret_eq_nonconst(const struct secret *a,
@@ -47,7 +47,7 @@ static struct timerel nonconst_time_test(struct secret *s1,
4747
struct secret *s2,
4848
size_t off)
4949
{
50-
struct timeabs start, end;
50+
struct timemono start, end;
5151
int result = 0;
5252

5353
memset(s1, 0, RUNS * sizeof(*s1));
@@ -56,16 +56,16 @@ static struct timerel nonconst_time_test(struct secret *s1,
5656
for (size_t i = 0; i < RUNS; i++)
5757
s2[i].data[off] = i;
5858

59-
start = time_now();
59+
start = time_mono();
6060
for (size_t i = 0; i < RUNS; i++)
6161
result += secret_eq_nonconst(&s1[i], &s2[i]);
62-
end = time_now();
62+
end = time_mono();
6363

6464
if (result != RUNS / 256)
6565
errx(1, "Expected %u successes at offset %zu, not %u!",
6666
RUNS / 256, off, result);
6767

68-
return time_between(end, start);
68+
return timemono_between(end, start);
6969
}
7070

7171
static struct secret *s1, *s2;

onchaind/test/run-grind_feerate.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
111111
struct amount_sat fee;
112112
struct pubkey htlc_key;
113113
struct keyset *keys;
114-
struct timeabs start, end;
114+
struct timemono start, end;
115115
int iterations = 1000;
116116
u8 *spk = tal_arr(tmpctx, u8, 1);
117117
spk[0] = 0x00;
@@ -143,15 +143,15 @@ int main(int argc, char *argv[])
143143
max_possible_feerate = 250000;
144144
min_possible_feerate = max_possible_feerate + 1 - iterations;
145145

146-
start = time_now();
146+
start = time_mono();
147147
if (!grind_htlc_tx_fee(&fee, tx, &sig, wscript, 663))
148148
abort();
149-
end = time_now();
149+
end = time_mono();
150150
assert(amount_sat_eq(fee, AMOUNT_SAT(165750)));
151151
printf("%u iterations in %"PRIu64" msec = %"PRIu64" nsec each\n",
152152
iterations,
153-
time_to_msec(time_between(end, start)),
154-
time_to_nsec(time_divide(time_between(end, start), iterations)));
153+
time_to_msec(timemono_between(end, start)),
154+
time_to_nsec(time_divide(timemono_between(end, start), iterations)));
155155

156156
common_shutdown();
157157
return 0;

0 commit comments

Comments
 (0)