#![feature(test)] extern crate test; extern crate rand; extern crate merkle_test; use rand::Rng; use merkle_test::MerkleTree; use merkle_test::crypto_reexport::sha2::Sha256; fn random_sha256() -> [u8; 256] { let mut buffer = [0u8; 256]; rand::thread_rng().fill_bytes(&mut buffer); buffer } fn random_sha256_hashes(num: u64) -> Vec<[u8; 256]> { let mut buffer = Vec::new(); (0..num).for_each(|_| buffer.push(random_sha256())); buffer } #[bench] fn calculate_root_of_1024_hashes(b: &mut test::Bencher) { let hashes = random_sha256_hashes(1024); let mut tree = MerkleTree::new(Sha256::new()); hashes.iter().for_each(|hash| tree.add_hash(hash.to_vec())); b.iter(|| tree.root()) }