//! [`MerkleProof::verify`] Benchmark //! //! [`merkleproof::verify`]: https://docs.rs/merkle-lite/latest/merkle_lite/struct.MerkleProof.html#method.verify #[macro_use] extern crate bencher; use bencher::Bencher; use digest::generic_array::{ArrayLength, GenericArray}; use digest::{typenum, Digest, OutputSizeUser}; use merkle_lite::MerkleTree; const NR_LEAVES: usize = 100_000; const PROOF_LEAF_INDICES: [std::ops::Range; 5] = [0..2, 101..109, 90_098..90_102, 8_928..8_929, 35..36]; benchmark_main!(sha2, sha3); // With [SHA2] hash functions. // // [sha2]: https://crates.io/crates/sha3 benchmark_group!( sha2, proof_verify::, proof_verify::, proof_verify::, proof_verify::, ); // With [SHA3] hash functions. // // [sha3]: https://crates.io/crates/sha3 benchmark_group!( sha3, proof_verify::, proof_verify::, proof_verify::, proof_verify::, ); fn proof_verify(b: &mut Bencher) where N: ArrayLength, B: Digest, >::ArrayType: Copy, <::OutputSize as ArrayLength>::ArrayType: Copy, { let leaves = [GenericArray::::default(); NR_LEAVES]; let proof_leaf_indices: Vec<_> = PROOF_LEAF_INDICES.into_iter().flatten().collect(); let proof_leaf_hashes: Vec<_> = proof_leaf_indices .iter() .map(|index| (*index, &leaves[*index])) .collect(); // compose the Merkle tree from the leaves. let tree = MerkleTree::::from_iter(leaves.iter()); b.iter(|| { // verify the Merkle root for the proof of inclusion. assert_eq!( tree.proof(&proof_leaf_indices) .unwrap() .verify(&proof_leaf_hashes) .unwrap() .as_ref(), tree.root().unwrap(), ); }) }