diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 96af1da7..7cf8768a 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -14,6 +14,28 @@ concurrency: cancel-in-progress: true jobs: + codspeed: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: Install cargo-codspeed + uses: taiki-e/install-action@v2 + with: + tool: cargo-codspeed + - name: Build the benchmark target(s) + run: cargo codspeed build --profile profiling -p solar-bench bench + - name: Run the benchmarks + uses: CodSpeedHQ/action@v3 + with: + run: cargo codspeed run -p solar-bench bench + token: ${{ secrets.CODSPEED_TOKEN }} + iai: runs-on: ubuntu-latest env: diff --git a/Cargo.lock b/Cargo.lock index e8b0fad3..7d1655e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -568,6 +568,28 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +[[package]] +name = "codspeed" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "450a0e9df9df1c154156f4344f99d8f6f6e69d0fc4de96ef6e2e68b2ec3bce97" +dependencies = [ + "colored", + "libc", + "serde_json", +] + +[[package]] +name = "codspeed-criterion-compat" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb1a6cb9c20e177fde58cdef97c1c7c9264eb1424fe45c4fccedc2fb078a569" +dependencies = [ + "codspeed", + "colored", + "criterion", +] + [[package]] name = "color-eyre" version = "0.6.3" @@ -2545,7 +2567,7 @@ dependencies = [ name = "solar-bench" version = "0.1.0" dependencies = [ - "criterion", + "codspeed-criterion-compat", "iai-callgrind", "paste", "semver 1.0.23", diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 45ea57e3..d99c4b12 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -22,7 +22,7 @@ slang_solidity = "=0.18.3" semver.workspace = true [dev-dependencies] -criterion = "0.5" +criterion = { package = "codspeed-criterion-compat", version = "2.7" } iai-callgrind = "0.14" paste.workspace = true diff --git a/benches/benches/bench.rs b/benches/benches/bench.rs index cbaa1419..157954ed 100644 --- a/benches/benches/bench.rs +++ b/benches/benches/bench.rs @@ -18,12 +18,17 @@ fn parser_benches(c: &mut Criterion) { for &Source { name: sname, path: _, src } in get_srcs() { for &parser in PARSERS { let pname = parser.name(); + let mk_id = |id: &str| { + if PARSERS.len() == 1 { + format!("{sname}/lex") + } else { + format!("{sname}/{pname}/{id}") + } + }; if parser.can_lex() { - let id = format!("{sname}/{pname}/lex"); - g.bench_function(id, |b| b.iter(|| parser.lex(src))); + g.bench_function(mk_id("lex"), |b| b.iter(|| parser.lex(src))); } - let id = format!("{sname}/{pname}/parse"); - g.bench_function(id, |b| b.iter(|| parser.parse(src))); + g.bench_function(mk_id("parse"), |b| b.iter(|| parser.parse(src))); } eprintln!(); } diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 7bef4701..b00d18fe 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -6,7 +6,9 @@ use std::{ process::Stdio, }; -pub const PARSERS: &[&dyn Parser] = &[&Solc, &Solar, &Solang, &Slang]; +#[allow(unexpected_cfgs)] +pub const PARSERS: &[&dyn Parser] = + if cfg!(codspeed) { &[&Solar] } else { &[&Solc, &Solar, &Solang, &Slang] }; pub fn get_srcs() -> &'static [Source] { static CACHE: std::sync::OnceLock> = std::sync::OnceLock::new();