Skip to content

feat: benches using criterion #10805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Foundry Benchmarks

on:
workflow_dispatch:
inputs:
pr_number:
description: "PR number to comment on (optional)"
required: false
type: string

permissions:
contents: write
pull-requests: write

jobs:
benchmark:
name: Run Foundry Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: |
./

- name: Install foundryup
run: |
curl -L https://foundry.paradigm.xyz | bash
echo "$HOME/.foundry/bin" >> $GITHUB_PATH

- name: Install benchmark dependencies
run: |
cargo install cargo-criterion
cargo install criterion-table

- name: Run benchmarks
working-directory: ./benches
run: |
chmod +x run_benchmarks.sh
./run_benchmarks.sh

- name: Commit benchmark results
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add benches/LATEST.md
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Update benchmark results

🤖 Generated with [Foundry Benchmarks](https://github.com/${{ github.repository }}/actions)

Co-Authored-By: github-actions <[email protected]>"
git push
fi

- name: Read benchmark results
id: benchmark_results
run: |
if [ -f "benches/LATEST.md" ]; then
{
echo 'results<<EOF'
cat benches/LATEST.md
echo 'EOF'
} >> $GITHUB_OUTPUT
else
echo 'results=No benchmark results found.' >> $GITHUB_OUTPUT
fi

- name: Comment on PR
if: github.event.inputs.pr_number != ''
uses: actions/github-script@v7
with:
script: |
const prNumber = ${{ github.event.inputs.pr_number }};
const benchmarkResults = `${{ steps.benchmark_results.outputs.results }}`;

const comment = `## 📊 Foundry Benchmark Results

<details>
<summary>Click to view detailed benchmark results</summary>

${benchmarkResults}

</details>

---

🤖 This comment was automatically generated by the [Foundry Benchmarks workflow](https://github.com/${{ github.repository }}/actions).

To run benchmarks manually: Go to [Actions](https://github.com/${{ github.repository }}/actions/workflows/foundry-benchmarks.yml) → "Run workflow"`;

github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});

125 changes: 118 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"benches/",
"crates/anvil/",
"crates/anvil/core/",
"crates/anvil/rpc/",
Expand Down
35 changes: 35 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "foundry-bench"
version = "0.1.0"
edition = "2021"

[[bench]]
name = "forge_test"
path = "forge_test.rs"
harness = false

[[bench]]
name = "forge_build_no_cache"
path = "forge_build_no_cache.rs"
harness = false

[[bench]]
name = "forge_build_with_cache"
path = "forge_build_with_cache.rs"
harness = false

[dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
foundry-test-utils.workspace = true
foundry-config.workspace = true
foundry-compilers = { workspace = true, features = ["project-util"] }
eyre.workspace = true
serde.workspace = true
serde_json.workspace = true
tempfile.workspace = true
tokio = { workspace = true, features = ["full"] }
chrono = { version = "0.4", features = ["serde"] }
rayon.workspace = true

[dev-dependencies]
foundry-test-utils.workspace = true
Loading
Loading