//! [`MerkleTree::proof`] Benchmark //! //! [`merkletree::proof`]: https://docs.rs/merkle-lite/latest/merkle_lite/struct.MerkleTree.html#method.proof #[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, tree_proof::, tree_proof::, tree_proof::, tree_proof::, ); // With [SHA3] hash functions. // // [sha3]: https://crates.io/crates/sha3 benchmark_group!( sha3, tree_proof::, tree_proof::, tree_proof::, tree_proof::, ); fn tree_proof(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(); // compose the Merkle tree from the leaves. let tree = MerkleTree::::from_iter(leaves.iter()); b.iter(|| { // get the Merkle proof. assert!(tree.proof(&proof_leaf_indices).is_some()); }) }