tests: use timemono not time_now() for duration measurement.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -16,7 +16,7 @@ static struct timerel const_time_test(struct secret *s1,
|
||||
struct secret *s2,
|
||||
size_t off)
|
||||
{
|
||||
struct timeabs start, end;
|
||||
struct timemono start, end;
|
||||
int result = 0;
|
||||
|
||||
memset(s1, 0, RUNS * sizeof(*s1));
|
||||
@@ -25,16 +25,16 @@ static struct timerel const_time_test(struct secret *s1,
|
||||
for (size_t i = 0; i < RUNS; i++)
|
||||
s2[i].data[off] = i;
|
||||
|
||||
start = time_now();
|
||||
start = time_mono();
|
||||
for (size_t i = 0; i < RUNS; i++)
|
||||
result += secret_eq_consttime(&s1[i], &s2[i]);
|
||||
end = time_now();
|
||||
end = time_mono();
|
||||
|
||||
if (result != RUNS / 256)
|
||||
errx(1, "Expected %u successes at offset %zu, not %u!",
|
||||
RUNS / 256, off, result);
|
||||
|
||||
return time_between(end, start);
|
||||
return timemono_between(end, start);
|
||||
}
|
||||
|
||||
static inline bool secret_eq_nonconst(const struct secret *a,
|
||||
@@ -47,7 +47,7 @@ static struct timerel nonconst_time_test(struct secret *s1,
|
||||
struct secret *s2,
|
||||
size_t off)
|
||||
{
|
||||
struct timeabs start, end;
|
||||
struct timemono start, end;
|
||||
int result = 0;
|
||||
|
||||
memset(s1, 0, RUNS * sizeof(*s1));
|
||||
@@ -56,16 +56,16 @@ static struct timerel nonconst_time_test(struct secret *s1,
|
||||
for (size_t i = 0; i < RUNS; i++)
|
||||
s2[i].data[off] = i;
|
||||
|
||||
start = time_now();
|
||||
start = time_mono();
|
||||
for (size_t i = 0; i < RUNS; i++)
|
||||
result += secret_eq_nonconst(&s1[i], &s2[i]);
|
||||
end = time_now();
|
||||
end = time_mono();
|
||||
|
||||
if (result != RUNS / 256)
|
||||
errx(1, "Expected %u successes at offset %zu, not %u!",
|
||||
RUNS / 256, off, result);
|
||||
|
||||
return time_between(end, start);
|
||||
return timemono_between(end, start);
|
||||
}
|
||||
|
||||
static struct secret *s1, *s2;
|
||||
|
||||
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
|
||||
struct amount_sat fee;
|
||||
struct pubkey htlc_key;
|
||||
struct keyset *keys;
|
||||
struct timeabs start, end;
|
||||
struct timemono start, end;
|
||||
int iterations = 1000;
|
||||
u8 *spk = tal_arr(tmpctx, u8, 1);
|
||||
spk[0] = 0x00;
|
||||
@@ -143,15 +143,15 @@ int main(int argc, char *argv[])
|
||||
max_possible_feerate = 250000;
|
||||
min_possible_feerate = max_possible_feerate + 1 - iterations;
|
||||
|
||||
start = time_now();
|
||||
start = time_mono();
|
||||
if (!grind_htlc_tx_fee(&fee, tx, &sig, wscript, 663))
|
||||
abort();
|
||||
end = time_now();
|
||||
end = time_mono();
|
||||
assert(amount_sat_eq(fee, AMOUNT_SAT(165750)));
|
||||
printf("%u iterations in %"PRIu64" msec = %"PRIu64" nsec each\n",
|
||||
iterations,
|
||||
time_to_msec(time_between(end, start)),
|
||||
time_to_nsec(time_divide(time_between(end, start), iterations)));
|
||||
time_to_msec(timemono_between(end, start)),
|
||||
time_to_nsec(time_divide(timemono_between(end, start), iterations)));
|
||||
|
||||
common_shutdown();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user