Benchmarks
KSail includes automated benchmark regression testing to detect performance changes in pull requests that modify Go code.
Performance Trends
Section titled “Performance Trends”Loading benchmark data…
Regression Detection
Section titled “Regression Detection”| Setting | Value | Meaning |
|---|---|---|
alert-threshold | 150% | Marks benchmarks as regressed and posts a PR comment when ≥1.5× slower than baseline (never blocks CI on PRs) |
fail-threshold | 200% | Fails CI on non-PR runs (pushes to main, merge queue) when a benchmark is ≥2× slower than baseline |
On pull requests where benchmarks run and benchmark functions are discovered, a comment is posted only when the alert threshold is exceeded, highlighting the regressed benchmarks.
Benchmark results are also recorded in every CI workflow run summary. On pushes to main, results are auto-pushed to the benchmark-data branch.
Running Benchmarks Locally
Section titled “Running Benchmarks Locally”# Run all benchmarksgo test -bench=. -benchmem -run='^$' ./...
# Run a specific packagego test -bench=. -benchmem -run='^$' ./pkg/k8s/readiness/...Writing Effective Benchmarks
Section titled “Writing Effective Benchmarks”- Call
b.ReportAllocs()to track allocations - Use
b.ResetTimer()after expensive setup - Use
for b.Loop()style (Go 1.26+) - Use
b.TempDir()for reproducible temp files - Use table-driven scenarios to cover multiple input sizes
- Fail fast with
b.Fatalfon unexpected errors - Avoid
time.Sleep()inside benchmark loops — measure real CPU work, not timers - For I/O-bound benchmarks (e.g. tarball creation), run a warmup iteration before
b.ResetTimer()to prime the OS page cache