|
| 1 | +use std::collections::HashMap; |
| 2 | +use std::time::Instant; |
| 3 | + |
| 4 | +use rand::rngs::StdRng; |
| 5 | +use rand::SeedableRng; |
1 | 6 | use starknet_committer::block_committer::commit::commit_block;
|
2 |
| -use starknet_committer::block_committer::input::Config; |
3 |
| -use starknet_patricia_storage::map_storage::MapStorage; |
| 7 | +use starknet_committer::block_committer::input::{Config, ConfigImpl}; |
| 8 | +use starknet_committer::block_committer::state_diff_generator::generate_random_state_diff; |
| 9 | +use starknet_patricia::hash::hash_trait::HashOutput; |
| 10 | +use starknet_patricia_storage::map_storage::{BorrowedMapStorage, MapStorage}; |
4 | 11 | use tracing::info;
|
5 | 12 | use tracing::level_filters::LevelFilter;
|
6 | 13 | use tracing_subscriber::reload::Handle;
|
@@ -43,3 +50,40 @@ pub async fn commit(input: InputImpl, output_path: String, storage: MapStorage)
|
43 | 50 | output.contract_storage_root_hash, output.compiled_class_root_hash,
|
44 | 51 | );
|
45 | 52 | }
|
| 53 | + |
| 54 | +pub async fn run_storage_benchmark() { |
| 55 | + let n_iterations = 10; |
| 56 | + let seed = 42_u64; // Constant seed for reproducibility |
| 57 | + |
| 58 | + let mut rng = StdRng::seed_from_u64(seed); |
| 59 | + let mut total_time = 0; |
| 60 | + |
| 61 | + let mut storage = MapStorage::new(); |
| 62 | + let mut contracts_trie_root_hash = HashOutput::default(); |
| 63 | + let mut classes_trie_root_hash = HashOutput::default(); |
| 64 | + |
| 65 | + for i in 0..n_iterations { |
| 66 | + info!("Committer storage benchmark iteration {}/{}", i + 1, n_iterations); |
| 67 | + let input = InputImpl { |
| 68 | + state_diff: generate_random_state_diff(&mut rng), |
| 69 | + contracts_trie_root_hash, |
| 70 | + classes_trie_root_hash, |
| 71 | + config: ConfigImpl::default(), |
| 72 | + }; |
| 73 | + |
| 74 | + // commit block and write to storage |
| 75 | + let start = Instant::now(); |
| 76 | + let serialized_filled_forest = SerializedForest( |
| 77 | + commit_block(input, &mut storage).await.expect("Failed to commit the given block."), |
| 78 | + ); |
| 79 | + serialized_filled_forest.0.write_to_storage(&mut storage); |
| 80 | + let duration = start.elapsed(); |
| 81 | + total_time += duration.as_millis(); |
| 82 | + |
| 83 | + contracts_trie_root_hash = serialized_filled_forest.0.get_contract_root_hash(); |
| 84 | + classes_trie_root_hash = serialized_filled_forest.0.get_compiled_class_root_hash(); |
| 85 | + } |
| 86 | + |
| 87 | + let avg_millis = total_time as f64 / n_iterations as f64; |
| 88 | + info!("Average time: {:.2} milliseconds", avg_millis); |
| 89 | +} |
0 commit comments