chore: minor benchmark fixes
Bobbin Threadbare bobbinth@protonmail.com
Tue, 24 Dec 2024 01:12:51 -0800
3 files changed,
23 insertions(+),
19 deletions(-)
M
Makefile
→
Makefile
@@ -81,6 +81,10 @@ RUSTFLAGS="-C target-feature=+sve" cargo build --release
# --- 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
M
src/main.rs
→
src/main.rs
@@ -46,7 +46,7 @@ let now = Instant::now();
let tree = Smt::with_entries(entries)?; let elapsed = now.elapsed(); println!( - "Constructed a SMT with {} key-value pairs in {:.3} seconds", + "Constructed a SMT with {} key-value pairs in {:.1} seconds", size, elapsed.as_secs_f32(), );@@ -62,7 +62,8 @@ println!("Running an insertion benchmark:");
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::<u64>().to_be_bytes()); let test_value = [ONE, ONE, ONE, Felt::new(size + i)];@@ -73,11 +74,10 @@ insertion_times.push(elapsed.as_secs_f32());
} 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::<f32>() * 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::<f32>() * 10_f32, ); Ok(())@@ -103,7 +103,7 @@ tree.apply_mutations(mutations).unwrap();
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 @@ compute_elapsed.as_secs_f32(),
); 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 @@ apply_elapsed.as_secs_f32(),
); 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 @@ println!("Running a proof generation benchmark:");
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::<u64>().to_be_bytes()); let test_value = [ONE, ONE, ONE, Felt::new(size + i)]; tree.insert(test_key, test_value);@@ -149,11 +150,10 @@ insertion_times.push(elapsed.as_secs_f32());
} 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::<f32>() * 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::<f32>() * 10000_f32, ); Ok(())
M
src/merkle/mmr/partial.rs
→
src/merkle/mmr/partial.rs
@@ -303,7 +303,7 @@ };
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(());