golang-benchmark

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

1|Updated May 25, 2020
One-click install
npx skills add https://github.com/titaneric/dotfiles --skill golang-benchmark-titaneric
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-benchmark
Source: https://github.com/titaneric/dotfiles/tree/main/dot_agents/skills/golang-benchmark
Command: npx skills add https://github.com/titaneric/dotfiles --skill golang-benchmark-titaneric

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: Capture CPU, memory, and execution trace profiles directly from go test, then interpret them with pprof (top -cum, list, peek), escape analysis (-gcflags="-m"), and SSA/assembly inspection. - Statistical Comparison & CI Gating: Compare runs with benchstat (p-values, confidence intervals, filters, projections) and set up CI regression detection with benchdiff, cob, or gobenchdata, including noisy-neighbor mitigation and self-hosted runner tuning. - Use Case: After optimizing a JSON parser, run both versions with -count=10, compare with benchstat, and paste the statistically significant result into the commit body so reviewers can verify the claimed 33% speedup. ## Quick Start Ask the agent to write a benchmark for your hot function, run it with -count=10 and -benchmem, then compare the before and after results 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 correctly in Go 1.24?

Use the b.Loop() loop construct, which times only the loop body and keeps results alive so the compiler cannot eliminate the work. Place setup code before the loop; no b.ResetTimer() or sink variables are needed.

How do I compare two Go benchmark runs statistically?

Run each version with go test -bench=... -benchmem -count=10, saving output to files, then compare with benchstat old.txt new.txt. Trust only results with p<0.05; a ~ symbol means no significant difference.

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

alloc_objects counts 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-hosted runners?

Shared CI runners show 5-10% variance from noisy neighbors, thermal throttling, and differing hardware. 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, while trace reveals goroutine scheduling delays, blocking, and GC phases. Extract blocking profiles with go tool trace -pprof=net.

Is it safe to run cob locally for 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.