golang-benchmark

Write, run, and statistically compare Go benchmarks with pprof profiling and CI regression detection.

1|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/rockcookies/skills --skill golang-benchmark-rockcookies
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-benchmark
Source: https://github.com/rockcookies/skills/tree/main/skills/samber-golang/golang-benchmark
Command: npx skills add https://github.com/rockcookies/skills --skill golang-benchmark-rockcookies

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires benchstat, and includes references (resource) components.

What problem does it solve? Go developers often draw wrong performance conclusions from single benchmark runs, noisy CI environments, or misread pprof profiles. This Skill provides a rigorous measurement methodology covering benchmark authoring, statistical comparison, profiling, and regression gating so optimization decisions rest on trustworthy data. ## Core Features & Use Cases - Benchmark Authoring: Write benchmarks using Go 1.24+ b.Loop(), memory tracking with b.ReportAllocs(), custom metrics via b.ReportMetric(), and table-driven sub-benchmarks. - Statistical Comparison: Compare before/after runs with benchstat, interpret p-values and confidence intervals, interleave runs to eliminate systematic bias, and avoid p-hacking traps. - Profiling & Diagnostics: Generate CPU, memory, and execution trace profiles from benchmarks, analyze escape analysis and inlining decisions with compiler flags, and investigate production issues with Prometheus runtime metrics. - CI Regression Detection: Gate pull requests with benchdiff, cob, or gobenchdata, mitigate noisy-neighbor variance on shared runners, and tune self-hosted runners for reproducible results. - Use Case: After optimizing a JSON parser, run go test -bench=. -count=10 on both versions, compare with benchstat, and paste the statistically significant results into the commit message to document the improvement. ## Quick Start Ask the AI to write a benchmark for your Go function using b.Loop() and then compare the optimized version against the baseline with benchstat.

Frequently Asked Questions about golang-benchmark

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Go benchmark with b.Loop()?▼

Place setup code before the loop, then call `for b.Loop() { YourFunc(input) }` inside a Benchmark function in a `_bench_test.go` file. b.Loop() times only the loop body and prevents dead code elimination, so no b.ResetTimer() or sink variable is needed.

How to compare Go benchmark results with benchstat?▼

Run each version with `go test -bench=. -benchmem -count=10` and save output to files, then run `benchstat old.txt new.txt`. Check the p-value: below 0.05 means statistically significant, while a `~` symbol means the difference is indistinguishable from noise.

What is the difference between alloc_objects and inuse_space in pprof heap profiles?▼

alloc_objects counts all allocation events since program start, making it right for diagnosing GC churn from high allocation rates. inuse_space shows only currently live heap objects, making it the correct choice for memory leak detection.

Why are my CI benchmark results inconsistent across runs?▼

Shared CI runners produce 5-10% variance from noisy neighbors, thermal throttling, and CPU frequency scaling. Mitigate by comparing base and head in the same job, using -count=10 with benchstat, setting conservative 20% thresholds, or using dedicated self-hosted runners.

When should I use go tool trace instead of pprof?▼

Use the execution tracer when pprof shows low CPU but latency is high, meaning goroutines are waiting rather than computing. Trace reveals scheduling delays, blocking on I/O or channels, and GC phases that CPU profiles cannot show.

Does cob work safely for local benchmark regression checks?▼

No, cob uses `git reset` internally, which can destroy uncommitted changes, and it compares single runs without statistical analysis. Commit all work first and prefer running cob only in CI pipelines; use benchdiff locally instead.