CLI
Discover and run benchmarks defined with @bench or Bench.
pybench run <files|directories> [options]# aliaspyb run <...>- Directories expand to
**/*bench.py. - Colors enabled on TTY; use
--no-colorto disable.
Options
Section titled “Options”-k <word> # filter by substring in case/file name-P k=v # override params: n, repeat, warmup, group and custom params (repeatable)--no-color # disable ANSI colors--sort [group|time] # sort groups or by avg time within group--desc # descending order--budget 300ms # per-variant budget (calibration). Accepts ns, ms, s--max-n 1000000 # cap for calibrated n--profile [thorough|smoke]--brief # compact output: benchmark, time(avg), vs base--save LABEL # save this run under .pybenchx/runs with optional label--save-baseline NAME # save this run as a named baseline under .pybenchx/baselines--compare BASE|PATH # compare current run against a baseline name or JSON file--vs {name,last} # shortcut for --compare; "last" targets the most recent auto-saved run--fail-on POLICY # e.g. "mean:7%,p99:12%"; checked when --compare/--vs is used--export FMT[:PATH] # export as json|md|csv|chart to stdout or a file when a path is givenProfiles:
- thorough:
budget≈1s,repeat=30 - smoke (default): no calibration,
repeat=3,warmup=0
Overrides with -P
Section titled “Overrides with -P”pybench run examples/ -P repeat=5 -P n=10000 -P warmup=0pybench run examples/ -P group=stringspybench run examples/ -P sep=":" # override a case parameterSorting and brief mode
Section titled “Sorting and brief mode”pybench run examples/ --sort time --descpybench run examples/ --briefHeader and table
Section titled “Header and table”- Header: CPU, Python, clock resolution, profile.
- Table: mean, iter/s, min…max, p75/p99/p995, baseline and speed vs base. “≈ same” when ≤1% diff.
Run management
Section titled “Run management”- Runs auto-save under
.pybenchx/runs/; named baselines live under.pybenchx/baselines/. - Use
--save/--save-baselinefor explicit labels,--compareor--vs {name,last}for comparisons, and--fail-onto enforce policies. - Inspect history with
pybench list, view storage totals withpybench stats, and prune older runs viapybench clean --keep N. - P-values are computed via Mann–Whitney U (approx).
p99policy uses the actual P99 delta.
Exporting Markdown
Section titled “Exporting Markdown”Generate a Markdown table you can paste into docs or discussions:
pybench run path/ --export md:bench.mdExporting charts
Section titled “Exporting charts”Create a self-contained HTML dashboard powered by Chart.js:
pybench run path/ --export chart:run.htmlTip: use --profile smoke while iterating; switch to thorough for published runs.