Skip to content

Benchmarks

KSail includes automated benchmark regression testing to detect performance changes in pull requests that modify Go code.

Loading benchmark data…

SettingValueMeaning
alert-threshold150%Marks benchmarks as regressed and posts a PR comment when ≥1.5× slower than baseline (never blocks CI on PRs)
fail-threshold200%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.

Terminal window
# Run all benchmarks
go test -bench=. -benchmem -run='^$' ./...
# Run a specific package
go test -bench=. -benchmem -run='^$' ./pkg/k8s/readiness/...
  • 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.Fatalf on 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