Skip to content

Commit 9fe47b1

Browse files
committed
tests: use timemono not time_now() for duration measurement.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 7b03963 commit 9fe47b1

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
@@ -22,7 +22,7 @@ static struct timerel const_time_test(struct secret *s1,
2222
struct secret *s2,
2323
size_t off)
2424
{
25-
struct timeabs start, end;
25+
struct timemono start, end;
2626
int result = 0;
2727

2828
memset(s1, 0, RUNS * sizeof(*s1));
@@ -31,16 +31,16 @@ static struct timerel const_time_test(struct secret *s1,
3131
for (size_t i = 0; i < RUNS; i++)
3232
s2[i].data[off] = i;
3333

34-
start = time_now();
34+
start = time_mono();
3535
for (size_t i = 0; i < RUNS; i++)
3636
result += secret_eq_consttime(&s1[i], &s2[i]);
37-
end = time_now();
37+
end = time_mono();
3838

3939
if (result != RUNS / 256)
4040
errx(1, "Expected %u successes at offset %zu, not %u!",
4141
RUNS / 256, off, result);
4242

43-
return time_between(end, start);
43+
return timemono_between(end, start);
4444
}
4545

4646
static inline bool secret_eq_nonconst(const struct secret *a,
@@ -53,7 +53,7 @@ static struct timerel nonconst_time_test(struct secret *s1,
5353
struct secret *s2,
5454
size_t off)
5555
{
56-
struct timeabs start, end;
56+
struct timemono start, end;
5757
int result = 0;
5858

5959
memset(s1, 0, RUNS * sizeof(*s1));
@@ -62,16 +62,16 @@ static struct timerel nonconst_time_test(struct secret *s1,
6262
for (size_t i = 0; i < RUNS; i++)
6363
s2[i].data[off] = i;
6464

65-
start = time_now();
65+
start = time_mono();
6666
for (size_t i = 0; i < RUNS; i++)
6767
result += secret_eq_nonconst(&s1[i], &s2[i]);
68-
end = time_now();
68+
end = time_mono();
6969

7070
if (result != RUNS / 256)
7171
errx(1, "Expected %u successes at offset %zu, not %u!",
7272
RUNS / 256, off, result);
7373

74-
return time_between(end, start);
74+
return timemono_between(end, start);
7575
}
7676

7777
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
@@ -356,7 +356,7 @@ int main(int argc, char *argv[])
356356
struct amount_sat fee;
357357
struct pubkey htlc_key;
358358
struct keyset *keys;
359-
struct timeabs start, end;
359+
struct timemono start, end;
360360
int iterations = 1000;
361361
u8 *spk = tal_arr(tmpctx, u8, 1);
362362
spk[0] = 0x00;
@@ -388,15 +388,15 @@ int main(int argc, char *argv[])
388388
max_possible_feerate = 250000;
389389
min_possible_feerate = max_possible_feerate + 1 - iterations;
390390

391-
start = time_now();
391+
start = time_mono();
392392
if (!grind_htlc_tx_fee(&fee, tx, &sig, wscript, 663))
393393
abort();
394-
end = time_now();
394+
end = time_mono();
395395
assert(amount_sat_eq(fee, AMOUNT_SAT(165750)));
396396
printf("%u iterations in %"PRIu64" msec = %"PRIu64" nsec each\n",
397397
iterations,
398-
time_to_msec(time_between(end, start)),
399-
time_to_nsec(time_divide(time_between(end, start), iterations)));
398+
time_to_msec(timemono_between(end, start)),
399+
time_to_nsec(time_divide(timemono_between(end, start), iterations)));
400400

401401
common_shutdown();
402402
return 0;

0 commit comments

Comments
 (0)