A comprehensive benchmark suite for measuring Rust compilation performance across multiple projects and optimization strategies.
- π¦ Three reference projects β small (embedded/generated code), medium (ripgrep), large (rust-analyzer)
- π€ Auto-detect mode β point at any Rust project; the tool analyses it and picks sensible parameters
- πΎ YAML config files β save/reload any benchmark configuration
- β‘ 13 built-in optimization profiles β baseline, incremental, sccache, LTO, codegen-units, parallel frontend, Cranelift, mold linker, nightly, and more
- π N runs with optional warmup β discard warmup runs to reduce noise
- π§ Interactive wizard β guided configuration via terminal prompts
- π Direct CLI β all options available as command-line flags
- π HTML reports with Chart.js diagrams β build time comparison, crate timings, per-project analysis
- π¦ JSON result storage β re-generate reports without re-running benchmarks
π€ Contributing via AI assistants? See
AGENTS.mdfor guidance for GitHub Copilot, Claude, and other coding agents.
# Required
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Rust
# Go 1.21+: https://go.dev/dl/
# Optional
cargo install sccache # for sccache profile
rustup toolchain install nightly # for nightly profiles
# mold linker: https://github.com/rui314/mold (for mold profile)cd bench
go build -o bench-tool .
# or: go run main.go [command]bash scripts/check-deps.shcd bench && go run main.go wizardThe wizard guides you through selecting projects, optimization profiles, run counts, and output options.
# List available projects and profiles
go run main.go list
# Quick smoke test
go run main.go run --projects small --profiles baseline --runs 1 --warmup 0
# Compare optimization profiles
go run main.go run \
--projects small \
--profiles baseline,incremental,lto-thin,codegen-units-max,debug-info-off \
--runs 3 --warmup 1 \
--cargo-profile dev
# Run with nightly profiles (requires nightly toolchain)
go run main.go run --projects small --profiles baseline,nightly-baseline,parallel-frontend --runs 3
# Generate report from existing results
go run main.go report
go run main.go report --open # open in browserPoint the CLI at any Rust project on disk and it will analyse the codebase
(size, workspace layout, build.rs, dependencies, available toolchains) and
pick reasonable benchmark parameters automatically:
# Analyse + run benchmarks with auto-detected parameters
go run main.go auto /path/to/my-rust-project
# Print analysis + recommendation without running
go run main.go auto /path/to/my-rust-project --dry-run
# Auto-detect, save the recommendation, then exit
go run main.go auto /path/to/my-rust-project --dry-run --save-config my-bench.yaml
# Override the auto-picked runs/warmup
go run main.go auto /path/to/my-rust-project --runs 5 --warmup 2The analyser uses a lightweight Cargo.toml parser plus a fast file walker and does not build the project during analysis.
Persist any configuration (from run, auto, or the wizard) to a YAML file
and reload it later:
# Save the effective configuration from a run
go run main.go run --projects small --profiles baseline,incremental \
--runs 3 --save-config ./my-bench.yaml
# Re-run exactly the same benchmark later
go run main.go run --config ./my-bench.yaml
# Load config, but override one value from the CLI
go run main.go run --config ./my-bench.yaml --runs 5Config files are human-editable YAML; they reference built-in projects by ID
(small, medium, large) or carry absolute paths for user-supplied projects
under custom_projects:.
Taskfile (optional β requires task)
task list # list available tasks
task bench # launch wizard
task bench:quick # fast smoke test
task bench:compare # key profiles comparison
task bench:nightly # nightly toolchain comparison
task bench:sccache # sccache benchmark
task report # generate report
task check # verify dependencies| ID | Name | Size | Description |
|---|---|---|---|
small |
embedded-sensor-node | small | Custom embedded no_std project with build.rs code generation (CRC tables, sine lookup, ADC calibration, register maps) |
medium |
ripgrep | medium | BurntSushi/ripgrep v14.1.1 β fast recursive grep tool (~15k LoC Rust) |
large |
rust-analyzer | large | rust-lang/rust-analyzer 2025-01-13 β Rust language server (~350k LoC Rust) |
# Medium project (ripgrep)
bash projects/medium/setup.sh
# Large project (rust-analyzer)
bash projects/large/setup.sh
# Or both at once
cd bench && go run main.go setup all| ID | Toolchain | Description |
|---|---|---|
baseline |
stable | Default cargo build |
incremental |
stable | CARGO_INCREMENTAL=1 |
no-incremental |
stable | CARGO_INCREMENTAL=0 |
sccache |
stable | RUSTC_WRAPPER=sccache β compiler cache |
lto-thin |
stable | -C lto=thin |
lto-fat |
stable | -C lto=fat β full LTO |
codegen-units-1 |
stable | -C codegen-units=1 β max optimization |
codegen-units-max |
stable | -C codegen-units=256 β max parallelism |
parallel-frontend |
nightly | -Z threads=8 β parallel compiler frontend |
cranelift |
nightly | -Z codegen-backend=cranelift |
mold |
stable | -C link-arg=-fuse-ld=mold β mold linker |
debug-info-off |
stable | -C debuginfo=0 |
nightly-baseline |
nightly | Nightly toolchain, no extra flags |
Use all to run all profiles: --profiles all
bench [command] [flags]
Commands:
wizard Interactive wizard to configure and run a benchmark
run Run the benchmark suite with the given options
auto Analyse a Rust project and run benchmarks with auto-detected parameters
report Generate an HTML report from the latest results
setup Clone and prepare reference projects
list List available projects and optimization profiles
Run flags:
--projects strings Projects to benchmark: small,medium,large,all (default [small])
--profiles strings Optimization profiles, comma-separated IDs or 'all' (default [baseline])
--runs int Number of measured runs per combination (default 3)
--warmup int Number of warmup runs, discarded (default 1)
--cargo-profile string Cargo build profile: dev or release (default "dev")
--clean Clean build artifacts between runs (default true)
--timings Collect crate timings via --timings=json (default true)
--output string Output directory (default <repo>/results)
--config string Load benchmark configuration from a YAML file
--save-config string Save the effective configuration to a YAML file
Auto flags:
--dry-run Print analysis + recommendation without running
--save-config string Save the auto-detected configuration to YAML
--runs int Override auto-detected number of runs
--warmup int Override auto-detected number of warmup runs
--cargo-profile string Override auto-detected cargo profile
Report flags:
--input string Path to results JSON file (default: latest)
--open Open the report in the default browser
Results are written to the results/ directory:
results-<timestamp>.jsonβ raw results in JSON formatreport-<timestamp>.htmlβ HTML report with Chart.js diagrams
- Summary β total runs, success rate, fastest/slowest build
- Overall comparison chart β bar chart of all profiles across projects
- Per-project analysis β tabbed view with:
- Build time comparison chart
- Profile statistics table (avg/min/max, speedup vs baseline)
- Crate timing breakdown (slowest crates)
- Raw results table β all individual runs
rust-compile-bench/
βββ AGENTS.md # Guidance for AI coding agents (Copilot / Claude / β¦)
βββ bench/ # Go CLI tool
β βββ main.go
β βββ cmd/ # cobra commands (run, auto, wizard, report, setup, list)
β βββ internal/
β βββ config/ # project/profile configuration types + YAML file load/save
β βββ autodetect/ # Rust project analyser + parameter recommender
β βββ runner/ # cargo build executor + result storage
β βββ report/ # HTML report generator
β β βββ templates/ # report.html (Chart.js template)
β βββ wizard/ # interactive terminal wizard
βββ projects/
β βββ small/ # Embedded sensor node (bundled, no setup needed)
β β βββ Cargo.toml
β β βββ build.rs # generates CRC/sine/ADC lookup tables + register maps
β β βββ src/ # adc, comm, dsp, scheduler, sensors modules
β βββ medium/
β β βββ setup.sh # clones ripgrep v14.1.1
β βββ large/
β βββ setup.sh # clones rust-analyzer 2025-01-13
βββ results/ # benchmark results (JSON + HTML, gitignored by default)
βββ scripts/
β βββ check-deps.sh # dependency checker
βββ Taskfile.yml # task orchestration (optional)
βββ .gitignore
cd bench && go test ./...cd bench && go build -ldflags="-s -w" -o bench-tool .