Skip to content

Commit e0b95f1

Browse files
committed
benchmarks: add benchmarks for checksum param generation
Mainly to confirm that these are really expensive (on my system, mulitple milliseconds for the descriptor checksum) and that we should precompute these values rather than suggesting users compute them at run-time whenever they want to do correction (which would result in a simpler API).
1 parent cce8a7a commit e0b95f1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/primitives/checksum.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,40 @@ mod tests {
588588
println!("{}", _s);
589589
}
590590
}
591+
592+
#[cfg(bench)]
593+
mod benches {
594+
use std::io::{sink, Write};
595+
596+
use test::{black_box, Bencher};
597+
598+
use crate::{Fe1024, Fe32, Fe32768, PrintImpl};
599+
600+
#[bench]
601+
fn compute_bech32_params(bh: &mut Bencher) {
602+
bh.iter(|| {
603+
let im = PrintImpl::<Fe1024>::new(
604+
"Bech32",
605+
&[Fe32::A, Fe32::K, Fe32::_5, Fe32::_4, Fe32::A, Fe32::J],
606+
&[Fe32::Q, Fe32::Q, Fe32::Q, Fe32::Q, Fe32::Q, Fe32::P],
607+
);
608+
let res = write!(sink(), "{}", im);
609+
black_box(&im);
610+
black_box(&res);
611+
})
612+
}
613+
614+
#[bench]
615+
fn compute_descriptor_params(bh: &mut Bencher) {
616+
bh.iter(|| {
617+
let im = PrintImpl::<Fe32768>::new(
618+
"DescriptorChecksum",
619+
&[Fe32::_7, Fe32::H, Fe32::_0, Fe32::W, Fe32::_2, Fe32::X, Fe32::V, Fe32::F],
620+
&[Fe32::Q, Fe32::Q, Fe32::Q, Fe32::Q, Fe32::Q, Fe32::Q, Fe32::Q, Fe32::P],
621+
);
622+
let res = write!(sink(), "{}", im);
623+
black_box(&im);
624+
black_box(&res);
625+
})
626+
}
627+
}

0 commit comments

Comments
 (0)