Browse Source

chore: minor benchmark fixes

next
Bobbin Threadbare 3 months ago
parent
commit
ef3183fc0b
No known key found for this signature in database GPG Key ID: 289C444AD87BC941
3 changed files with 23 additions and 19 deletions
  1. +6
    -2
      Makefile
  2. +16
    -16
      src/main.rs
  3. +1
    -1
      src/merkle/mmr/partial.rs

+ 6
- 2
Makefile

@ -81,6 +81,10 @@ build-sve: ## Build with sve support
# --- benchmarking -------------------------------------------------------------------------------- # --- benchmarking --------------------------------------------------------------------------------
.PHONY: bench-tx
bench-tx: ## Run crypto benchmarks
.PHONY: bench
bench: ## Run crypto benchmarks
cargo bench --features="concurrent" 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

+ 16
- 16
src/main.rs

@ -46,7 +46,7 @@ pub fn construction(entries: Vec<(RpoDigest, Word)>, size: u64) -> Result
let tree = Smt::with_entries(entries)?; let tree = Smt::with_entries(entries)?;
let elapsed = now.elapsed(); let elapsed = now.elapsed();
println!( println!(
"Constructed a SMT with {} key-value pairs in {:.3} seconds",
"Constructed a SMT with {} key-value pairs in {:.1} seconds",
size, size,
elapsed.as_secs_f32(), elapsed.as_secs_f32(),
); );
@ -62,7 +62,8 @@ pub fn insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> {
let mut insertion_times = Vec::new(); 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_key = Rpo256::hash(&rand_value::<u64>().to_be_bytes());
let test_value = [ONE, ONE, ONE, Felt::new(size + i)]; 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!( 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(()) Ok(())
@ -103,7 +103,7 @@ pub fn batched_insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> {
let apply_elapsed = now.elapsed(); let apply_elapsed = now.elapsed();
println!( 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, size,
compute_elapsed.as_secs_f32() * 1000f32, compute_elapsed.as_secs_f32() * 1000f32,
// Dividing by the number of iterations, 1000, and then multiplying by 1000 to get // 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!( 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, size,
apply_elapsed.as_secs_f32() * 1000f32, apply_elapsed.as_secs_f32() * 1000f32,
// Dividing by the number of iterations, 1000, and then multiplying by 1000 to get // 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!( 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, size,
(compute_elapsed + apply_elapsed).as_secs_f32() * 1000f32, (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(); 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_key = Rpo256::hash(&rand_value::<u64>().to_be_bytes());
let test_value = [ONE, ONE, ONE, Felt::new(size + i)]; let test_value = [ONE, ONE, ONE, Felt::new(size + i)];
tree.insert(test_key, test_value); tree.insert(test_key, test_value);
@ -149,11 +150,10 @@ pub fn proof_generation(tree: &mut Smt, size: u64) -> Result<(), MerkleError> {
} }
println!( 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(()) Ok(())

+ 1
- 1
src/merkle/mmr/partial.rs

@ -303,7 +303,7 @@ impl PartialMmr {
if leaf_pos + 1 == self.forest if leaf_pos + 1 == self.forest
&& path.depth() == 0 && 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; self.track_latest = true;
return Ok(()); return Ok(());

Loading…
Cancel
Save