diff --git a/Makefile b/Makefile index 8ab23d1..3927443 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,10 @@ build-sve: ## Build with sve support # --- benchmarking -------------------------------------------------------------------------------- -.PHONY: bench-tx -bench-tx: ## Run crypto benchmarks +.PHONY: bench +bench: ## Run crypto benchmarks cargo bench --features="concurrent" + +.PHONY: bench-smt-concurrent +bench-smt-concurrent: ## Run SMT benchmarks with concurrent feature + cargo run --release --features concurrent,executable -- --size 1000000 diff --git a/src/main.rs b/src/main.rs index 776ccc2..7fccdb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ pub fn construction(entries: Vec<(RpoDigest, Word)>, size: u64) -> Result Result<(), MerkleError> { let mut insertion_times = Vec::new(); - for i in 0..20 { + const N: u64 = 100; + for i in 0..N { let test_key = Rpo256::hash(&rand_value::().to_be_bytes()); let test_value = [ONE, ONE, ONE, Felt::new(size + i)]; @@ -73,11 +74,10 @@ pub fn insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> { } println!( - "An average insertion time measured by 20 inserts into a SMT with {} key-value pairs is {:.3} milliseconds\n", - size, - // calculate the average by dividing by 20 and convert to milliseconds by multiplying by - // 1000. As a result, we can only multiply by 50 - insertion_times.iter().sum::() * 50f32, + "An average insertion time measured by {N} inserts into a SMT with {size} key-value pairs is {:.1} ms\n", + // calculate the average by dividing by 100 and convert to milliseconds by multiplying by + // 1000. As a result, we can only multiply by 10 + insertion_times.iter().sum::() * 10_f32, ); Ok(()) @@ -103,7 +103,7 @@ pub fn batched_insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> { let apply_elapsed = now.elapsed(); println!( - "An average batch computation time measured by a 1k-batch into an SMT with {} key-value pairs over {:.3} milliseconds is {:.3} milliseconds", + "An average batch computation time measured by a 1k-batch into an SMT with {} key-value pairs over {:.1} ms is {:.3} ms", size, compute_elapsed.as_secs_f32() * 1000f32, // Dividing by the number of iterations, 1000, and then multiplying by 1000 to get @@ -112,7 +112,7 @@ pub fn batched_insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> { ); println!( - "An average batch application time measured by a 1k-batch into an SMT with {} key-value pairs over {:.3} milliseconds is {:.3} milliseconds", + "An average batch application time measured by a 1k-batch into an SMT with {} key-value pairs over {:.1} ms is {:.3} ms", size, apply_elapsed.as_secs_f32() * 1000f32, // Dividing by the number of iterations, 1000, and then multiplying by 1000 to get @@ -121,7 +121,7 @@ pub fn batched_insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> { ); println!( - "An average batch insertion time measured by a 1k-batch into an SMT with {} key-value pairs totals to {:.3} milliseconds", + "An average batch insertion time measured by a 1k-batch into an SMT with {} key-value pairs totals to {:.1} ms", size, (compute_elapsed + apply_elapsed).as_secs_f32() * 1000f32, ); @@ -137,7 +137,8 @@ pub fn proof_generation(tree: &mut Smt, size: u64) -> Result<(), MerkleError> { let mut insertion_times = Vec::new(); - for i in 0..20 { + const N: u64 = 100; + for i in 0..N { let test_key = Rpo256::hash(&rand_value::().to_be_bytes()); let test_value = [ONE, ONE, ONE, Felt::new(size + i)]; tree.insert(test_key, test_value); @@ -149,11 +150,10 @@ pub fn proof_generation(tree: &mut Smt, size: u64) -> Result<(), MerkleError> { } println!( - "An average proving time measured by 20 value proofs in a SMT with {} key-value pairs in {:.3} microseconds", - size, - // calculate the average by dividing by 20 and convert to microseconds by multiplying by - // 1000000. As a result, we can only multiply by 50000 - insertion_times.iter().sum::() * 50000f32, + "An average proving time measured by {N} value proofs in a SMT with {size} key-value pairs is {:.1} μs", + // calculate the average by dividing by 100 and convert to microseconds by multiplying by + // 1000000. As a result, we can only multiply by 10000 + insertion_times.iter().sum::() * 10000_f32, ); Ok(()) diff --git a/src/merkle/mmr/partial.rs b/src/merkle/mmr/partial.rs index 5327548..b29c4f5 100644 --- a/src/merkle/mmr/partial.rs +++ b/src/merkle/mmr/partial.rs @@ -303,7 +303,7 @@ impl PartialMmr { if leaf_pos + 1 == self.forest && path.depth() == 0 - && self.peaks.last().map_or(false, |v| *v == leaf) + && self.peaks.last().is_some_and(|v| *v == leaf) { self.track_latest = true; return Ok(());