Skip to content

Commit

Permalink
Pass benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
amosStarkware committed Jul 30, 2024
1 parent 6886488 commit 8d101ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn get_random_u256<R: Rng>(rng: &mut R, low: U256, high: U256) -> U256 {
}

pub async fn tree_computation_flow(
leaf_modifications: Arc<LeafModifications<StarknetStorageValue>>,
leaf_modifications: LeafModifications<StarknetStorageValue>,
storage: &MapStorage,
root_hash: HashOutput,
) -> StorageTrie {
Expand Down Expand Up @@ -98,7 +98,7 @@ pub async fn tree_computation_flow(

StorageTrie::create_no_additional_output::<TreeHashFunctionImpl>(
updated_skeleton.into(),
leaf_modifications,
Arc::new(leaf_modifications),
)
.await
.expect("Failed to create the filled tree")
Expand All @@ -115,8 +115,7 @@ pub async fn single_tree_flow_test(
.map(|(k, v)| (NodeIndex::FIRST_LEAF + k, v))
.collect::<LeafModifications<StarknetStorageValue>>();

let filled_tree =
tree_computation_flow(Arc::new(leaf_modifications), &storage, root_hash).await;
let filled_tree = tree_computation_flow(leaf_modifications, &storage, root_hash).await;

let hash_result = filled_tree.get_root_hash();

Expand Down
25 changes: 14 additions & 11 deletions crates/committer_cli/benches/committer_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Then upload the new files to GCS with this new prefix (run e.g.,
// gcloud storage cp LOCAL_FILE gs://committer-testing-artifacts/NEW_PREFIX/tree_flow_inputs.json).

use std::{collections::HashMap, sync::Arc};
use std::collections::HashMap;

use committer::{
block_committer::input::StarknetStorageValue,
Expand All @@ -17,7 +17,7 @@ use committer::{
},
};
use committer_cli::{commands::parse_and_commit, tests::utils::parse_from_python::TreeFlowInput};
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};

const CONCURRENCY_MODE: bool = true;
const SINGLE_TREE_FLOW_INPUT: &str = include_str!("tree_flow_inputs.json");
Expand All @@ -42,16 +42,19 @@ pub fn single_tree_flow_benchmark(criterion: &mut Criterion) {
.into_iter()
.map(|(k, v)| (NodeIndex::FIRST_LEAF + k, v))
.collect::<LeafModifications<StarknetStorageValue>>();
let arc_leaf_modifications = Arc::new(leaf_modifications);

criterion.bench_function("tree_computation_flow", |benchmark| {
benchmark.iter(|| {
runtime.block_on(tree_computation_flow(
Arc::clone(&arc_leaf_modifications),
&storage,
root_hash,
));
})
criterion.bench_function("tree_computation_flow", move |b| {
b.iter_batched(
|| leaf_modifications.clone(),
|leaf_modifications_input| {
runtime.block_on(tree_computation_flow(
leaf_modifications_input,
&storage,
root_hash,
));
},
BatchSize::LargeInput,
)
});
}

Expand Down

0 comments on commit 8d101ff

Please sign in to comment.