@kaynooo/cli-bench
v0.2.1
Published
bench: command and HTTP benchmarking with git-ref regression comparison and baseline diffing.
Maintainers
Readme
@kaynooo/cli-bench
bench benchmarks shell commands and HTTP endpoints, compares performance against any git ref in a temporary linked worktree, and diffs saved benchmark JSON baselines with statistical significance testing (Welch's t-test).
bun add -g @kaynooo/cli-bench| Command | What it does |
| --- | --- |
| bench -- <cmd...> | benchmark a command (shorthand for bench run) |
| bench run -n 20 -w 3 -- <cmd...> | run 3 warmups and 20 timed iterations, printing min, median, mean, stddev, p95, p99, max, a sparkline and a distribution histogram |
| bench --cmd "a" --cmd "b" | compare multiple commands side-by-side, ranked fastest first with speedup ratios and Welch's t-test significance |
| bench run --min-time 2s --prepare "rm -rf .cache" -- <cmd...> | keep running until at least 2s of timed work completes, running a setup command before each iteration |
| bench run --save baseline.json -- <cmd...> | write structured JSON results for later bench diff |
| bench compare -- <cmd...> | benchmark <cmd> at HEAD (in a temporary linked git worktree) interleaved with the current working tree, reporting deltas and Welch's t-test p-value |
| bench compare --base main --fail-on-regression 10 -- <cmd...> | exit 1 when the working tree has a statistically significant median slowdown over 10% |
| bench compare --base v1.0 --head v1.1 -- <cmd...> | compare two git refs directly |
| bench http -c 10 -n 100 <url> | concurrent HTTP load test reporting req/s, status code breakdown, error count, transfer size, latency percentiles and distribution bars |
| bench http -c 20 -d 5s -H "Accept: application/json" <url> | sustained load test for a fixed duration (-d) instead of a fixed request count (-n) |
| bench http -m POST --body '{"ok":true}' --max-error-rate 1 <url> | send a request body (--body / --data) and exit 1 if the failed request percentage exceeds 1% |
| bench diff baseline.json current.json | compare two saved benchmark JSON outputs and report per-benchmark median/p95 deltas and regression verdicts (--threshold, default 5%) |
Git-ref comparison (bench compare)
bench compare checks out --base (default HEAD) — and --head when given — into temporary detached git worktrees under the system temp directory. Gitignored .env* files and dependency folders (node_modules, vendor, .venv) are symlinked from the main checkout so commands run without reinstalling dependencies (pass --no-link to isolate completely). Temporary worktrees are always removed on exit or signal interruption.
Warmup and timed runs are interleaved between base and head (alternating order on each pair) to reduce CPU throttling and background drift bias. Significance is tested with a two-tailed Welch's unequal-variances t-test ($\alpha = 0.05$).
JSON output and baselines
Every subcommand accepts --json for machine-readable output, and run, compare, and http accept --save <file> to write the same JSON report to disk. bench diff <baseline.json> <current.json> reads outputs from bench run, bench http, or bench compare (saved via --save or redirected from --json), matches benchmarks by name, and exits 1 when any benchmark's median slows down past --threshold (default 5%).
Exit codes
0: benchmark completed cleanly (no failing regressions or error-rate violations)1: a command failed, all HTTP requests failed, HTTP error rate exceeded--max-error-rate, or a regression exceeded--fail-on-regression/--threshold2: usage error, invalid URL/header/JSON, missing file, not inside a git repository, or unknown git ref127: command could not be started
