Skip to content

Commit

Permalink
feat: set up codspeed
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 12, 2024
1 parent b962d57 commit afd6961
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 24 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions benches/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
Expand Down
4 changes: 3 additions & 1 deletion benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Source>> = std::sync::OnceLock::new();
Expand Down

0 comments on commit afd6961

Please sign in to comment.