diff --git a/src/main.rs b/src/main.rs index 776ccc2..d362b7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::time::Instant; use clap::Parser; use miden_crypto::{ hash::rpo::{Rpo256, RpoDigest}, - merkle::{MerkleError, Smt}, + merkle::{MerkleError, NodeIndex, Smt}, Felt, Word, ONE, }; use rand_utils::rand_value; @@ -33,7 +33,9 @@ pub fn benchmark_smt() { entries.push((key, value)); } - let mut tree = construction(entries, tree_size).unwrap(); + let mut tree = construction(entries.clone(), tree_size).unwrap(); + let parallel = parallel_construction(entries, tree_size).unwrap(); + assert_eq!(tree, parallel); insertion(&mut tree, tree_size).unwrap(); batched_insertion(&mut tree, tree_size).unwrap(); proof_generation(&mut tree, tree_size).unwrap(); @@ -56,6 +58,31 @@ pub fn construction(entries: Vec<(RpoDigest, Word)>, size: u64) -> Result, + size: u64, +) -> Result { + println!("Running a parallel construction benchmark:"); + let now = Instant::now(); + + let (inner_nodes, leaves) = Smt::build_subtrees(entries); + let root = inner_nodes.get(&NodeIndex::root()).unwrap().hash(); + + let leaves = leaves.into_iter().map(|(key, value)| (key.value(), value)).collect(); + + let tree = Smt::from_raw_parts(inner_nodes, leaves, root)?; + + let elapsed = now.elapsed(); + println!( + "Parallel-constructed an SMT with {} key-value pairs in {:.3} seconds", + size, + elapsed.as_secs_f32(), + ); + println!("Number of leaf nodes: {}\n", tree.leaves().count()); + + Ok(tree) +} + /// Runs the insertion benchmark for the [`Smt`]. pub fn insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> { println!("Running an insertion benchmark:");