From da947073203cdf78fc9e27db12d850ac92dfabe5 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:46:46 +0200 Subject: [PATCH] chore: replace criterion with divan (#9080) --- Cargo.lock | 237 +++++++++--------------- Cargo.toml | 52 +++--- Dockerfile | 2 +- crates/cast/Cargo.toml | 5 +- crates/cast/benches/vanity.rs | 53 ++---- crates/chisel/Cargo.toml | 5 - crates/chisel/benches/session_source.rs | 84 --------- crates/forge/Cargo.toml | 5 - crates/forge/benches/test.rs | 29 --- 9 files changed, 130 insertions(+), 342 deletions(-) delete mode 100644 crates/chisel/benches/session_source.rs delete mode 100644 crates/forge/benches/test.rs diff --git a/Cargo.lock b/Cargo.lock index 7438ab7f1acb..ff25d3ac6460 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -792,12 +792,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "anstream" version = "0.6.15" @@ -1929,9 +1923,61 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +version = "0.2.0" +dependencies = [ + "alloy-chains", + "alloy-consensus", + "alloy-contract", + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-json-rpc", + "alloy-network", + "alloy-primitives", + "alloy-provider", + "alloy-rlp", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", + "alloy-sol-types", + "alloy-transport", + "anvil", + "async-trait", + "aws-sdk-kms", + "chrono", + "clap", + "clap_complete", + "clap_complete_fig", + "comfy-table", + "divan", + "dunce", + "evmole", + "eyre", + "foundry-block-explorers", + "foundry-cli", + "foundry-common", + "foundry-compilers", + "foundry-config", + "foundry-evm", + "foundry-test-utils", + "foundry-wallets", + "futures", + "indicatif", + "itertools 0.13.0", + "rand", + "rayon", + "regex", + "rpassword", + "semver 1.0.23", + "serde", + "serde_json", + "tempfile", + "tikv-jemallocator", + "tokio", + "tracing", + "vergen", + "yansi", +] [[package]] name = "castaway" @@ -1978,7 +2024,6 @@ dependencies = [ "alloy-primitives", "alloy-rpc-types", "clap", - "criterion", "dirs 5.0.1", "eyre", "forge-fmt", @@ -2297,6 +2342,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + [[package]] name = "console" version = "0.15.8" @@ -2382,44 +2433,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "criterion" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" -dependencies = [ - "anes", - "cast", - "ciborium", - "clap", - "criterion-plot", - "futures", - "is-terminal", - "itertools 0.10.5", - "num-traits", - "once_cell", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "tokio", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools 0.10.5", -] - [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -2818,6 +2831,31 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "divan" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d567df2c9c2870a43f3f2bd65aaeb18dbce1c18f217c3e564b4fbaeb3ee56c" +dependencies = [ + "cfg-if", + "clap", + "condtype", + "divan-macros", + "libc", + "regex-lite", +] + +[[package]] +name = "divan-macros" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27540baf49be0d484d8f0130d7d8da3011c32a44d4fc873368154f1510e574a2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "doctest-file" version = "1.0.0" @@ -3317,7 +3355,6 @@ dependencies = [ "clap_complete_fig", "clearscreen", "comfy-table", - "criterion", "dialoguer", "dunce", "ethers-contract-abigen", @@ -3540,64 +3577,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "foundry-cast" -version = "0.2.0" -dependencies = [ - "alloy-chains", - "alloy-consensus", - "alloy-contract", - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-json-rpc", - "alloy-network", - "alloy-primitives", - "alloy-provider", - "alloy-rlp", - "alloy-rpc-types", - "alloy-serde", - "alloy-signer", - "alloy-signer-local", - "alloy-sol-types", - "alloy-transport", - "anvil", - "async-trait", - "aws-sdk-kms", - "chrono", - "clap", - "clap_complete", - "clap_complete_fig", - "comfy-table", - "criterion", - "dunce", - "evmole", - "eyre", - "foundry-block-explorers", - "foundry-cli", - "foundry-common", - "foundry-compilers", - "foundry-config", - "foundry-evm", - "foundry-test-utils", - "foundry-wallets", - "futures", - "indicatif", - "itertools 0.13.0", - "rand", - "rayon", - "regex", - "rpassword", - "semver 1.0.23", - "serde", - "serde_json", - "tempfile", - "tikv-jemallocator", - "tokio", - "tracing", - "vergen", - "yansi", -] - [[package]] name = "foundry-cheatcodes" version = "0.2.0" @@ -6050,12 +6029,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "oorandom" -version = "11.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" - [[package]] name = "op-alloy-consensus" version = "0.3.3" @@ -6544,34 +6517,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" -[[package]] -name = "plotters" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" - -[[package]] -name = "plotters-svg" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" -dependencies = [ - "plotters-backend", -] - [[package]] name = "portable-atomic" version = "1.9.0" @@ -8604,16 +8549,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "1.8.0" diff --git a/Cargo.toml b/Cargo.toml index 9b660adbb1dc..02b364e8332d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -223,13 +223,20 @@ alloy-trie = "0.6.0" op-alloy-rpc-types = "0.3.3" op-alloy-consensus = "0.3.3" -## misc -async-trait = "0.1" -auto_impl = "1" -walkdir = "2" +# macros proc-macro2 = "1.0.82" quote = "1.0" syn = "2.0" +async-trait = "0.1" +derive_more = { version = "1.0", features = ["full"] } +thiserror = "1" + +# bench +divan = "0.1" + +# misc +auto_impl = "1" +walkdir = "2" prettyplease = "0.2.20" ahash = "0.8" base64 = "0.22" @@ -237,47 +244,44 @@ chrono = { version = "0.4", default-features = false, features = [ "clock", "std", ] } +axum = "0.7" color-eyre = "0.6" -derive_more = { version = "1.0", features = ["full"] } +comfy-table = "7" dunce = "1" evm-disassembler = "0.5" +evmole = "0.5" eyre = "0.6" figment = "0.10" futures = "0.3" +hyper = "1.0" +indexmap = "2.2" itertools = "0.13" jsonpath_lib = "0.3" k256 = "0.13" -parking_lot = "0.12" mesc = "0.3" +num-format = "0.4.4" +parking_lot = "0.12" +proptest = "1" rand = "0.8" +rayon = "1" +reqwest = { version = "0.12", default-features = false } semver = "1" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", features = ["arbitrary_precision"] } similar-asserts = "1.5" +soldeer-commands = "=0.4.0" strum = "0.26" -thiserror = "1" +tempfile = "3.10" +tikv-jemallocator = "0.6" +tokio = "1" toml = "0.8" +tower = "0.4" +tower-http = "0.5" tracing = "0.1" tracing-subscriber = "0.3" -vergen = { version = "8", default-features = false } -indexmap = "2.2" -tikv-jemallocator = "0.6" url = "2" -num-format = "0.4.4" +vergen = { version = "8", default-features = false } yansi = { version = "1.0", features = ["detect-tty", "detect-env"] } -tempfile = "3.10" -tokio = "1" -rayon = "1" -evmole = "0.5" -axum = "0.7" -hyper = "1.0" -reqwest = { version = "0.12", default-features = false } -tower = "0.4" -tower-http = "0.5" -# soldeer -soldeer-commands = "=0.4.0" -proptest = "1" -comfy-table = "7" [patch.crates-io] ## alloy-core diff --git a/Dockerfile b/Dockerfile index 87e52b70861c..14415acbcf18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ COPY . . RUN git update-index --force-write-index RUN --mount=type=cache,target=/root/.cargo/registry --mount=type=cache,target=/root/.cargo/git --mount=type=cache,target=/opt/foundry/target \ - source $HOME/.profile && cargo build --release --features foundry-cast/aws-kms,forge/aws-kms \ + source $HOME/.profile && cargo build --release --features cast/aws-kms,forge/aws-kms \ && mkdir out \ && mv target/release/forge out/forge \ && mv target/release/cast out/cast \ diff --git a/crates/cast/Cargo.toml b/crates/cast/Cargo.toml index 9f0b6758c11c..5fadb49675ce 100644 --- a/crates/cast/Cargo.toml +++ b/crates/cast/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "foundry-cast" +name = "cast" description = "Command-line tool for performing Ethereum RPC calls" version.workspace = true @@ -89,8 +89,9 @@ tikv-jemallocator = { workspace = true, optional = true } [dev-dependencies] anvil.workspace = true foundry-test-utils.workspace = true + async-trait.workspace = true -criterion = "0.5" +divan.workspace = true [features] default = ["rustls", "jemalloc"] diff --git a/crates/cast/benches/vanity.rs b/crates/cast/benches/vanity.rs index 4311b5283a74..a39e4d8bcabf 100644 --- a/crates/cast/benches/vanity.rs +++ b/crates/cast/benches/vanity.rs @@ -1,51 +1,22 @@ -use criterion::{criterion_group, criterion_main, Criterion}; use rayon::prelude::*; -use std::{hint::black_box, time::Duration}; +use std::hint::black_box; #[path = "../bin/cmd/wallet/mod.rs"] #[allow(unused)] mod wallet; use wallet::vanity::*; -/// Benches `cast wallet vanity` -/// -/// Left or right matchers, with or without nonce do not change the outcome. -/// -/// Regex matchers get optimised away even with a black_box. -fn vanity(c: &mut Criterion) { - let mut g = c.benchmark_group("vanity"); - - g.sample_size(500); - g.noise_threshold(0.04); - g.measurement_time(Duration::from_secs(30)); - - g.bench_function("wallet generator", |b| b.iter(|| black_box(generate_wallet()))); - - // 1 - - g.sample_size(100); - g.noise_threshold(0.02); - - g.bench_function("match 1", |b| { - let m = LeftHexMatcher { left: vec![0] }; - let matcher = create_matcher(m); - b.iter(|| wallet_generator().find_any(|x| black_box(matcher(x)))) - }); - - // 2 - - g.sample_size(10); - g.noise_threshold(0.01); - g.measurement_time(Duration::from_secs(60)); - - g.bench_function("match 2", |b| { - let m = LeftHexMatcher { left: vec![0, 0] }; - let matcher = create_matcher(m); - b.iter(|| wallet_generator().find_any(|x| black_box(matcher(x)))) - }); +#[divan::bench] +fn vanity_wallet_generator() -> GeneratedWallet { + generate_wallet() +} - g.finish(); +#[divan::bench(args = [&[0][..]])] +fn vanity_match(bencher: divan::Bencher<'_, '_>, arg: &[u8]) { + let matcher = create_matcher(LeftHexMatcher { left: arg.to_vec() }); + bencher.bench_local(|| wallet_generator().find_any(|x| black_box(matcher(x)))); } -criterion_group!(vanity_benches, vanity); -criterion_main!(vanity_benches); +fn main() { + divan::main(); +} diff --git a/crates/chisel/Cargo.toml b/crates/chisel/Cargo.toml index 5d8ad4d2c4dd..7868137d85ca 100644 --- a/crates/chisel/Cargo.toml +++ b/crates/chisel/Cargo.toml @@ -68,7 +68,6 @@ tracing.workspace = true tikv-jemallocator = { workspace = true, optional = true } [dev-dependencies] -criterion = { version = "0.5", features = ["async_tokio"] } serial_test = "3" tracing-subscriber.workspace = true @@ -78,7 +77,3 @@ rustls = ["reqwest/rustls-tls", "reqwest/rustls-tls-native-roots"] openssl = ["foundry-compilers/openssl", "reqwest/default-tls"] asm-keccak = ["alloy-primitives/asm-keccak"] jemalloc = ["dep:tikv-jemallocator"] - -[[bench]] -name = "session_source" -harness = false diff --git a/crates/chisel/benches/session_source.rs b/crates/chisel/benches/session_source.rs deleted file mode 100644 index 49d127c4728e..000000000000 --- a/crates/chisel/benches/session_source.rs +++ /dev/null @@ -1,84 +0,0 @@ -use chisel::session_source::{SessionSource, SessionSourceConfig}; -use criterion::{criterion_group, Criterion}; -use foundry_compilers::solc::Solc; -use semver::Version; -use std::{hint::black_box, sync::LazyLock}; -use tokio::runtime::Runtime; - -static SOLC: LazyLock = - LazyLock::new(|| Solc::find_or_install(&Version::new(0, 8, 19)).unwrap()); - -/// Benchmark for the `clone_with_new_line` function in [SessionSource] -fn clone_with_new_line(c: &mut Criterion) { - let mut g = c.benchmark_group("session_source"); - - // Grab an empty session source - g.bench_function("clone_with_new_line", |b| { - b.iter(|| { - let session_source = get_empty_session_source(); - let new_line = String::from("uint a = 1"); - black_box(session_source.clone_with_new_line(new_line).unwrap()); - }) - }); -} - -/// Benchmark for the `build` function in [SessionSource] -fn build(c: &mut Criterion) { - let mut g = c.benchmark_group("session_source"); - - g.bench_function("build", |b| { - b.iter(|| { - // Grab an empty session source - let mut session_source = get_empty_session_source(); - black_box(session_source.build().unwrap()) - }) - }); -} - -/// Benchmark for the `execute` function in [SessionSource] -fn execute(c: &mut Criterion) { - let mut g = c.benchmark_group("session_source"); - - g.bench_function("execute", |b| { - b.to_async(rt()).iter(|| async { - // Grab an empty session source - let mut session_source = get_empty_session_source(); - black_box(session_source.execute().await.unwrap()) - }) - }); -} - -/// Benchmark for the `inspect` function in [SessionSource] -fn inspect(c: &mut Criterion) { - let mut g = c.benchmark_group("session_source"); - - g.bench_function("inspect", |b| { - b.to_async(rt()).iter(|| async { - // Grab an empty session source - let mut session_source = get_empty_session_source(); - // Add a uint named "a" with value 1 to the session source - session_source.with_run_code("uint a = 1"); - black_box(session_source.inspect("a").await.unwrap()) - }) - }); -} - -/// Helper function for getting an empty [SessionSource] with default configuration -fn get_empty_session_source() -> SessionSource { - SessionSource::new(SOLC.clone(), SessionSourceConfig::default()) -} - -fn rt() -> Runtime { - Runtime::new().unwrap() -} - -fn main() { - // Install before benches if not present - let _ = LazyLock::force(&SOLC); - - session_source_benches(); - - Criterion::default().configure_from_args().final_summary() -} - -criterion_group!(session_source_benches, clone_with_new_line, build, execute, inspect); diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index 0e359191aabf..1b716497a45e 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -117,7 +117,6 @@ anvil.workspace = true foundry-test-utils.workspace = true mockall = "0.13" -criterion = "0.5" globset = "0.4" paste = "1.0" path-slash = "0.2" @@ -143,7 +142,3 @@ asm-keccak = ["alloy-primitives/asm-keccak"] jemalloc = ["dep:tikv-jemallocator"] aws-kms = ["foundry-wallets/aws-kms"] isolate-by-default = ["foundry-config/isolate-by-default"] - -[[bench]] -name = "test" -harness = false diff --git a/crates/forge/benches/test.rs b/crates/forge/benches/test.rs deleted file mode 100644 index 593bce3d320d..000000000000 --- a/crates/forge/benches/test.rs +++ /dev/null @@ -1,29 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; -use foundry_test_utils::{ - util::{lossy_string, setup_forge_remote}, - TestCommand, TestProject, -}; - -/// Returns a cloned and `forge built` `solmate` project -fn built_solmate() -> (TestProject, TestCommand) { - setup_forge_remote("transmissions11/solmate") -} - -fn forge_test_benchmark(c: &mut Criterion) { - let (prj, _) = built_solmate(); - - let mut group = c.benchmark_group("forge test"); - group.sample_size(10); - group.bench_function("solmate", |b| { - let mut cmd = prj.forge_command(); - cmd.arg("test"); - b.iter(|| { - let output = cmd.execute(); - println!("stdout:\n{}", lossy_string(&output.stdout)); - println!("\nstderr:\n{}", lossy_string(&output.stderr)); - }); - }); -} - -criterion_group!(benches, forge_test_benchmark); -criterion_main!(benches);