Skip to content

Commit

Permalink
feat: use criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
hhamud committed Apr 24, 2024
1 parent 184ef0b commit 39ad3c6
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 75 deletions.
154 changes: 147 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ keywords = ["starknet", "cairo", "testnet", "local", "server"]


[workspace.dependencies]

# axum
axum = { version = "0.5" }
hyper = "0.14.12"
Expand Down Expand Up @@ -107,3 +108,6 @@ lazy_static = { version = "1.4.0" }
ethers = { version = "2.0.11" }

openssl = { version = "0.10", features = ["vendored"] }



7 changes: 7 additions & 0 deletions crates/starknet-devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ starknet-rs-core = { workspace = true }
starknet-rs-accounts = { workspace = true }
hyper = { workspace = true }
usc = { workspace = true }
criterion = { version = "0.3.4", features = ["async_tokio"] }


[[bench]]
name = "mint_bench"
harness = false
path = "tests/benches/mint_bench.rs"
4 changes: 1 addition & 3 deletions crates/starknet-devnet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ pub(crate) struct Args {
#[arg(long = "account-class-custom")]
#[arg(value_name = "PATH")]
#[arg(conflicts_with = "account_class_choice")]
#[arg(
help = "Specify the path to a Cairo Sierra artifact to be used by predeployed accounts;"
)]
#[arg(help = "Specify the path to a Cairo Sierra artifact to be used by predeployed accounts;")]
account_class_custom: Option<AccountClassWrapper>,

/// Initial balance of predeployed accounts
Expand Down
36 changes: 36 additions & 0 deletions crates/starknet-devnet/tests/benches/mint_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion, SamplingMode};
use tokio::runtime::Runtime;

use crate::common::background_devnet::BackgroundDevnet;

#[path = "../common/mod.rs"]
pub mod common;

static DUMMY_ADDRESS: u128 = 1;
static DUMMY_AMOUNT: u128 = 1;

async fn mint_iter(f: &str) {
let devnet =
BackgroundDevnet::spawn_with_additional_args(&[
format!("--state-archive-capacity={}", f).as_str()
])
.await
.expect("Could not start Devnet");

for _n in 1..5000 {
devnet.mint(DUMMY_ADDRESS, DUMMY_AMOUNT).await;
}
}

fn bench_memory(c: &mut Criterion) {
let rt = Runtime::new().unwrap();
let mut group = c.benchmark_group("Mint");
group.significance_level(0.1).sample_size(10);
group.bench_function("full", |b| b.to_async(&rt).iter(|| black_box(mint_iter("full"))));
group.bench_function("none", |b| b.to_async(&rt).iter(|| black_box(mint_iter("none"))));

group.finish();
}

criterion_group!(benches, bench_memory);
criterion_main!(benches);
16 changes: 8 additions & 8 deletions crates/starknet-devnet/tests/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub fn get_flattened_sierra_contract_and_casm_hash(
(sierra_class.flatten().unwrap(), casm_hash(casm_json).unwrap())
}

pub fn get_messaging_contract_in_sierra_and_compiled_class_hash(
) -> (FlattenedSierraClass, FieldElement) {
pub fn get_messaging_contract_in_sierra_and_compiled_class_hash()
-> (FlattenedSierraClass, FieldElement) {
let sierra_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/cairo1/messaging/cairo_1_l1l2.sierra");
get_flattened_sierra_contract_and_casm_hash(sierra_path)
Expand All @@ -81,24 +81,24 @@ pub fn get_messaging_lib_in_sierra_and_compiled_class_hash() -> (FlattenedSierra
get_flattened_sierra_contract_and_casm_hash(sierra_path)
}

pub fn get_events_contract_in_sierra_and_compiled_class_hash(
) -> (FlattenedSierraClass, FieldElement) {
pub fn get_events_contract_in_sierra_and_compiled_class_hash()
-> (FlattenedSierraClass, FieldElement) {
let events_sierra_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/cairo1/events/events_2.0.1_compiler.sierra"
);
get_flattened_sierra_contract_and_casm_hash(events_sierra_path)
}

pub fn get_block_reader_contract_in_sierra_and_compiled_class_hash(
) -> (FlattenedSierraClass, FieldElement) {
pub fn get_block_reader_contract_in_sierra_and_compiled_class_hash()
-> (FlattenedSierraClass, FieldElement) {
let timestamp_sierra_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/cairo1/block_reader/block_reader.sierra");
get_flattened_sierra_contract_and_casm_hash(timestamp_sierra_path)
}

pub fn get_simple_contract_in_sierra_and_compiled_class_hash(
) -> (FlattenedSierraClass, FieldElement) {
pub fn get_simple_contract_in_sierra_and_compiled_class_hash()
-> (FlattenedSierraClass, FieldElement) {
let contract_path = format!("{}/{}", env!("CARGO_MANIFEST_DIR"), CAIRO_1_CONTRACT_PATH);
get_flattened_sierra_contract_and_casm_hash(&contract_path)
}
Expand Down
Loading

0 comments on commit 39ad3c6

Please sign in to comment.