Skip to content

Commit 64baae2

Browse files
yash-atreyaclaude
andauthored
feat: benches using criterion (#10805)
* feat: criterion benches * - setup benchmark repos in parallel - run forge build in parallet for forge-test bench - switch foundry versions - README specifying prereqs * feat: shell script to run benches * feat: ci workflow, fix script * update readme * feat: enhance benchmarking suite with version flexibility - Add `get_benchmark_versions()` helper to read versions from env var - Update all benchmarks to use version helper for consistency - Add `--versions` and `--force-install` flags to shell script - Enable all three benchmarks (forge_test, build_no_cache, build_with_cache) - Improve error handling for corrupted forge installations - Remove complex workarounds in favor of clear error messages The benchmarks now support custom versions via: ./run_benchmarks.sh --versions stable,nightly,v1.2.0 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]> * latest bench * rm notes * remove shell based bench suite --------- Co-authored-by: Claude <[email protected]>
1 parent 01f1af6 commit 64baae2

16 files changed

+1124
-821
lines changed

.github/workflows/benchmarks.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Foundry Benchmarks
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: "PR number to comment on (optional)"
8+
required: false
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
benchmark:
17+
name: Run Foundry Benchmarks
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 60
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Rust toolchain
26+
uses: dtolnay/rust-toolchain@stable
27+
28+
- name: Cache Rust dependencies
29+
uses: Swatinem/rust-cache@v2
30+
with:
31+
workspaces: |
32+
./
33+
34+
- name: Install foundryup
35+
run: |
36+
curl -L https://foundry.paradigm.xyz | bash
37+
echo "$HOME/.foundry/bin" >> $GITHUB_PATH
38+
39+
- name: Install benchmark dependencies
40+
run: |
41+
cargo install cargo-criterion
42+
cargo install criterion-table
43+
44+
- name: Run benchmarks
45+
working-directory: ./benches
46+
run: |
47+
chmod +x run_benchmarks.sh
48+
./run_benchmarks.sh
49+
50+
- name: Commit benchmark results
51+
run: |
52+
git config --local user.email "[email protected]"
53+
git config --local user.name "GitHub Action"
54+
git add benches/LATEST.md
55+
if git diff --staged --quiet; then
56+
echo "No changes to commit"
57+
else
58+
git commit -m "Update benchmark results
59+
60+
🤖 Generated with [Foundry Benchmarks](https://github.com/${{ github.repository }}/actions)
61+
62+
Co-Authored-By: github-actions <[email protected]>"
63+
git push
64+
fi
65+
66+
- name: Read benchmark results
67+
id: benchmark_results
68+
run: |
69+
if [ -f "benches/LATEST.md" ]; then
70+
{
71+
echo 'results<<EOF'
72+
cat benches/LATEST.md
73+
echo 'EOF'
74+
} >> $GITHUB_OUTPUT
75+
else
76+
echo 'results=No benchmark results found.' >> $GITHUB_OUTPUT
77+
fi
78+
79+
- name: Comment on PR
80+
if: github.event.inputs.pr_number != ''
81+
uses: actions/github-script@v7
82+
with:
83+
script: |
84+
const prNumber = ${{ github.event.inputs.pr_number }};
85+
const benchmarkResults = `${{ steps.benchmark_results.outputs.results }}`;
86+
87+
const comment = `## 📊 Foundry Benchmark Results
88+
89+
<details>
90+
<summary>Click to view detailed benchmark results</summary>
91+
92+
${benchmarkResults}
93+
94+
</details>
95+
96+
---
97+
98+
🤖 This comment was automatically generated by the [Foundry Benchmarks workflow](https://github.com/${{ github.repository }}/actions).
99+
100+
To run benchmarks manually: Go to [Actions](https://github.com/${{ github.repository }}/actions/workflows/foundry-benchmarks.yml) → "Run workflow"`;
101+
102+
github.rest.issues.createComment({
103+
issue_number: prNumber,
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
body: comment
107+
});
108+

Cargo.lock

Lines changed: 118 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = [
3+
"benches/",
34
"crates/anvil/",
45
"crates/anvil/core/",
56
"crates/anvil/rpc/",

benches/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "foundry-bench"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bench]]
7+
name = "forge_test"
8+
path = "forge_test.rs"
9+
harness = false
10+
11+
[[bench]]
12+
name = "forge_build_no_cache"
13+
path = "forge_build_no_cache.rs"
14+
harness = false
15+
16+
[[bench]]
17+
name = "forge_build_with_cache"
18+
path = "forge_build_with_cache.rs"
19+
harness = false
20+
21+
[dependencies]
22+
criterion = { version = "0.5", features = ["html_reports"] }
23+
foundry-test-utils.workspace = true
24+
foundry-config.workspace = true
25+
foundry-compilers = { workspace = true, features = ["project-util"] }
26+
eyre.workspace = true
27+
serde.workspace = true
28+
serde_json.workspace = true
29+
tempfile.workspace = true
30+
tokio = { workspace = true, features = ["full"] }
31+
chrono = { version = "0.4", features = ["serde"] }
32+
rayon.workspace = true
33+
34+
[dev-dependencies]
35+
foundry-test-utils.workspace = true

0 commit comments

Comments
 (0)