CLI Recipes
Practical command-line workflows for running, checking, formatting, and integrating poly-bench
Practical command-line workflows for running, checking, formatting, and integrating poly-bench
This page covers practical CLI workflows — from first-run setup through CI integration. For the full flag reference, see the CLI Reference.
The standard sequence for a new project from scratch:
$# 1. Create a new project$poly-bench init my-benchmarks$cd my-benchmarks
$# 2. Add dependencies for each language you'll use$poly-bench add --go golang.org/x/crypto$poly-bench add --ts viem$poly-bench add --rs tiny-keccak
$# 3. Install all dependencies$poly-bench install
$# 4. Create a benchmark file$poly-bench new keccak
$# 5. Run it$poly-bench run benchmarks/keccak.bench --output results/After poly-bench init, the project looks like this:
1my-benchmarks/2├── polybench.toml # Project config and dependencies3├── benchmarks/4│ └── example.bench # Template benchmark5└── .polybench/6 └── runtime-env/ # Installed dependencies (gitignore this)$poly-bench run benchmarks/keccak.bench.bench files in benchmarks/$poly-bench run$# Save charts and reports to results/$poly-bench run benchmarks/keccak.bench --output results/
$# Save markdown report$poly-bench run benchmarks/keccak.bench --report markdown --output results/
$# Save JSON (for programmatic processing)$poly-bench run benchmarks/keccak.bench --report json --output results/
$# Save markdown then JSON (run twice)$poly-bench run benchmarks/keccak.bench --report markdown --output results/$poly-bench run benchmarks/keccak.bench --report json --output results/Run only the languages you care about. Useful during development when you're iterating on one implementation.
$# Run all languages (default)$poly-bench run benchmarks/keccak.bench
$# Run only Go$poly-bench run benchmarks/keccak.bench --lang go
$# Run only TypeScript$poly-bench run benchmarks/keccak.bench --lang ts
$# Run only Rust$poly-bench run benchmarks/keccak.bench --lang rust
$# Run Go and TypeScript, skip Rust$poly-bench run benchmarks/keccak.bench --lang go --lang ts
$# Run Go and Rust, skip TypeScript$poly-bench run benchmarks/keccak.bench --lang go --lang rust--lang go during development to get fast feedback on your Go implementation before wiring up TypeScript and Rust. Add the other languages once the benchmark logic is correct.Override the iteration count to run a fast sanity check without waiting for full auto-calibration.
$# Run exactly 100 iterations per benchmark (fast smoke test)$poly-bench run benchmarks/keccak.bench --iterations 100
$# Combine with language filter for maximum speed$poly-bench run benchmarks/keccak.bench --iterations 100 --lang goUse check to parse and validate a .bench file without compiling or executing anything. It catches syntax errors, undefined fixtures, and type mismatches.
$# Validate a single file$poly-bench check benchmarks/keccak.bench
$# Success output$✓ benchmarks/keccak.bench is valid
$# Error output$error: undefined fixture 'data' at line 42$--> benchmarks/keccak.bench:42:9$ |$42 | go: keccak256(data)$ | ^^^^^^^^^^^^^^$ = help: define a fixture named 'data' before using it$#!/bin/sh$# Validate all .bench files before committing$for f in benchmarks/*.bench; do$ poly-bench check "$f" || exit 1$donepoly-bench fmt formats .bench files with consistent indentation and spacing.
$# Print formatted output for a single file$poly-bench fmt benchmarks/keccak.bench
$# Format all .bench files in benchmarks/ (print to stdout)$poly-bench fmt
$# Write formatted output back to file(s)$poly-bench fmt benchmarks/keccak.bench --write$poly-bench fmt --write1- name: Format benchmark files2run: poly-bench fmt --writecodegen generates the benchmark harness code for a language without running it. Use this to debug what poly-bench is producing or to understand the generated structure.
$# Generate Go harness$poly-bench codegen benchmarks/keccak.bench --lang go --output generated/
$# Generate TypeScript harness$poly-bench codegen benchmarks/keccak.bench --lang ts --output generated/
$# Generate Rust harness$poly-bench codegen benchmarks/keccak.bench --lang rust --output generated/
$# Inspect the output$cat generated/benchmark_plugin.goGenerated files:
generated/benchmark_plugin.gogenerated/benchmark.tsgenerated/main.rsUse compile to type-check generated code for each language before running benchmarks.
$# Compile-check all benchmark files (uses cache by default)$poly-bench compile
$# Compile-check a single file/language$poly-bench compile benchmarks/keccak.bench --lang go
$# Force cold compile-check$poly-bench compile benchmarks/keccak.bench --no-cache --clear-cacheCache housekeeping:
1poly-bench cache stats2poly-bench cache clear3poly-bench cache cleanA complete GitHub Actions workflow that runs benchmarks, saves results, and uploads artifacts.
1name: Benchmarks2
3on:4push:5 branches: [main]6pull_request:7 branches: [main]8
9jobs:10bench:11 runs-on: ubuntu-latest12
13 steps:14 - uses: actions/checkout@v415
16 - name: Install Go17 uses: actions/setup-go@v518 with:19 go-version: "1.22"20
21 - name: Install Node.js22 uses: actions/setup-node@v423 with:24 node-version: "20"25
26 - name: Install Rust27 uses: dtolnay/rust-toolchain@stable28
29 - name: Install poly-bench30 run: curl -L https://install.evm-tooling.tools | bash31
32 - name: Install benchmark dependencies33 run: poly-bench install34
35 - name: Format benchmark files36 run: poly-bench fmt --write37
38 - name: Compile-check benchmark files39 run: poly-bench compile40
41 - name: Validate benchmark files42 run: |43 for f in benchmarks/*.bench; do44 poly-bench check "$f"45 done46
47 - name: Run benchmarks (markdown + json)48 run: |49 poly-bench run --report markdown --output results/50 poly-bench run --report json --output results/51
52 - name: Upload results53 uses: actions/upload-artifact@v454 with:55 name: benchmark-results56 path: results/Run benchmarks on both the base branch and the PR branch, then compare:
1name: Benchmark Comparison2
3on:4pull_request:5 branches: [main]6
7jobs:8bench-pr:9 runs-on: ubuntu-latest10 steps:11 - uses: actions/checkout@v412
13 - name: Install poly-bench14 run: curl -L https://install.evm-tooling.tools | bash15
16 - name: Install dependencies17 run: poly-bench install18
19 - name: Run benchmarks (PR)20 run: poly-bench run --report json --output results-pr/21
22 - name: Upload PR results23 uses: actions/upload-artifact@v424 with:25 name: bench-pr26 path: results-pr/27
28bench-base:29 runs-on: ubuntu-latest30 steps:31 - uses: actions/checkout@v432 with:33 ref: ${{ github.base_ref }}34
35 - name: Install poly-bench36 run: curl -L https://install.evm-tooling.tools | bash37
38 - name: Install dependencies39 run: poly-bench install40
41 - name: Run benchmarks (base)42 run: poly-bench run --report json --output results-base/43
44 - name: Upload base results45 uses: actions/upload-artifact@v446 with:47 name: bench-base48 path: results-base/| Goal | Command |
|---|---|
| Fast smoke test | poly-bench run bench.bench --iterations 100 --lang go |
| Full run with all outputs | poly-bench run bench.bench --report markdown --output results/ then poly-bench run bench.bench --report json --output results/ |
| Format benchmark files | poly-bench fmt --write |
| CI validation | poly-bench check benchmarks/*.bench |
| Compile-check before running | poly-bench compile bench.bench --lang go |
| Inspect generated Go code | poly-bench codegen bench.bench --lang go --output gen/ |
| Run with reduced logs | poly-bench run bench.bench --quiet |
| Override iterations | poly-bench run bench.bench --iterations 50000 |