diff --git a/Cargo.lock b/Cargo.lock index 801d60deb3..b607e161c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10434,6 +10434,7 @@ dependencies = [ "blockifier", "cairo-lang-sierra-to-casm", "cairo-lang-starknet-classes", + "criterion", "futures", "mempool_test_utils", "mockall", diff --git a/crates/starknet_gateway/Cargo.toml b/crates/starknet_gateway/Cargo.toml index 6420c9ba5e..e94b288aaf 100644 --- a/crates/starknet_gateway/Cargo.toml +++ b/crates/starknet_gateway/Cargo.toml @@ -39,6 +39,7 @@ validator.workspace = true [dev-dependencies] assert_matches.workspace = true cairo-lang-sierra-to-casm.workspace = true +criterion.workspace = true mockall.workspace = true mockito.workspace = true num-bigint.workspace = true @@ -49,3 +50,8 @@ rstest.workspace = true starknet_mempool.workspace = true starknet_mempool_types = { workspace = true, features = ["testing"] } tracing-test.workspace = true + +[[bench]] +harness = false +name = "gateway_bench" +path = "bench/gateway_bench.rs" diff --git a/crates/starknet_gateway/bench/gateway_bench.rs b/crates/starknet_gateway/bench/gateway_bench.rs new file mode 100644 index 0000000000..a28f74db34 --- /dev/null +++ b/crates/starknet_gateway/bench/gateway_bench.rs @@ -0,0 +1,37 @@ +//! Benchmark module for the starknet gateway crate. It provides functionalities to benchmark +//! the performance of the gateway service, including declare, deploy account and invoke +//! transactions. +//! +//! There are four benchmark functions in this flow: `declare_benchmark`, +//! `deploy_account_benchmark`, `invoke_benchmark` and `gateway_benchmark` which combines all of the +//! types. Each of the functions measure the performance of the gateway handling randomly created +//! txs of the respective type. +//! +//! Run the benchmarks using `cargo bench --bench gateway_bench`. + +use criterion::{criterion_group, criterion_main, Criterion}; + +pub fn declare_benchmark(c: &mut Criterion) { + c.bench_function("declares", |benchmark| benchmark.iter(|| {})); +} + +pub fn deploy_account_benchmark(c: &mut Criterion) { + c.bench_function("deploy_accounts", |benchmark| benchmark.iter(|| {})); +} + +pub fn invoke_benchmark(c: &mut Criterion) { + c.bench_function("invokes", |benchmark| benchmark.iter(|| {})); +} + +pub fn gateway_benchmark(c: &mut Criterion) { + c.bench_function("all_transaction_types", |benchmark| benchmark.iter(|| {})); +} + +criterion_group!( + benches, + declare_benchmark, + deploy_account_benchmark, + invoke_benchmark, + gateway_benchmark +); +criterion_main!(benches);