golang-benchmark

Measure, profile, and statistically compare Go benchmark performance with pprof and benchstat.

Updated Jun 15, 2026
One-click install
npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-benchmark-2877389577
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-benchmark
Source: https://github.com/2877389577/novels_ai_gen/tree/main/.agents/skills/golang-benchmark
Command: npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-benchmark-2877389577

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Go performance work fails when developers draw conclusions from single benchmark runs, misread pprof profiles, or cannot tell a real regression from CI noise. This Skill provides the full measurement methodology — writing correct benchmarks, profiling hot paths, and proving improvements with statistical rigor. ## Core Features & Use Cases - Benchmark Authoring: Write benchmarks with b.Loop() (Go 1.24+), memory tracking via b.ReportAllocs(), custom metrics via b.ReportMetric(), and table-driven sub-benchmarks. - Profiling & Analysis: Generate CPU, memory, and execution trace profiles directly from benchmarks, then interpret them with pprof commands, escape analysis, inlining diagnostics, and SSA/assembly inspection. - Statistical Comparison & CI Gating: Compare runs with benchstat (p-values, confidence intervals, filters), and set up CI regression detection with benchdiff, cob, or gobenchdata including noisy-runner mitigation. - Use Case: After optimizing a JSON parser, run go test -bench=. -count=10 before and after, compare with benchstat, and paste the statistically significant result into the commit message to document the improvement. ## Quick Start Ask the agent to write a Go 1.24 benchmark for your function, run it ten times with memory stats, and compare the results against your baseline using 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 use `for b.Loop() { YourFunc(input) }` inside the benchmark function. b.Loop() times only the loop body and prevents dead code elimination, so no b.ResetTimer() or sink variable is needed.

How do I 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`. A difference is real only when p<0.05; a `~` symbol means no statistically significant change.

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

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

Why are my CI benchmark results noisy on GitHub runners?▼

Shared CI runners show 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, and setting conservative 20% thresholds.

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

Use the execution tracer when latency is high but CPU profiles show low utilization — pprof only shows on-CPU time. Trace reveals goroutine scheduling delays, blocking on channels or I/O, and GC phases across a timeline.

How do I find why a Go variable escapes to the heap?▼

Run `go build -gcflags="-m -m"` on the package to see escape decisions with the full escape chain. Common causes include returning pointers to locals, interface boxing, and closures capturing variables.