add bench for base58::encode_check

This commit is contained in:
Riccardo Casatta 2024-05-10 11:12:41 +02:00
parent 0d627326ce
commit e4b707ba83
1 changed files with 30 additions and 0 deletions

View File

@ -19,6 +19,9 @@
#[macro_use] #[macro_use]
extern crate alloc; extern crate alloc;
#[cfg(bench)]
extern crate test;
#[cfg(feature = "std")] #[cfg(feature = "std")]
extern crate std; extern crate std;
@ -284,3 +287,30 @@ mod tests {
assert_eq!(decode_check(&encode(&[1, 2, 3])), Err(TooShortError { length: 3 }.into())); assert_eq!(decode_check(&encode(&[1, 2, 3])), Err(TooShortError { length: 3 }.into()));
} }
} }
#[cfg(bench)]
mod benches {
use test::{black_box, Bencher};
#[bench]
pub fn bench_encode_check_50(bh: &mut Bencher) {
let data: alloc::vec::Vec<_> = (0u8..50).collect();
bh.iter(|| {
let r = super::encode_check(&data);
black_box(&r);
});
}
#[bench]
pub fn bench_encode_check_xpub(bh: &mut Bencher) {
let data: alloc::vec::Vec<_> = (0u8..78).collect(); // lenght of xpub
bh.iter(|| {
let r = super::encode_check(&data);
black_box(&r);
});
}
}