golang-benchmark

Measure, profile, and compare Go benchmarks with benchstat and pprof.

1|Updated May 27, 2026
One-click install
npx skills add https://github.com/dmwin72015/netdisk --skill golang-benchmark-dmwin72015
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-benchmark
Source: https://github.com/dmwin72015/netdisk/tree/main/.agents/skills/golang-benchmark
Command: npx skills add https://github.com/dmwin72015/netdisk --skill golang-benchmark-dmwin72015

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill solves unreliable Go performance decisions by providing a rigorous workflow to measure, profile, compare, and interpret benchmark and profiling results without being misled by noise or dead-code elimination.

Core Features & Use Cases

  • Write correct Go benchmarks: use Go 1.24+ b.Loop() to prevent dead-code elimination mistakes, structure setup vs timed code, and report allocations and custom throughput metrics.
  • Run and capture measurable benchmark data: standardize benchmark flags (-benchmem, -count, -benchtime) and generate CPU/memory/trace profiles directly from benchmark runs.
  • Interpret results with confidence: use benchstat for A/B comparison, understand confidence intervals and the ~ (not statistically significant) signal, and avoid p-hacking.
  • Profile and diagnose bottlenecks: generate pprof CPU/heap/trace outputs from benchmarks, then guide interpretation (flat vs cumulative, GC churn vs leaks, and trace vs pprof selection).
  • Integrate regression detection into CI: choose appropriate tooling (benchdiff/ cob/ gobenchdata) for PR gating or long-term performance trend tracking.

Quick Start

Use the golang-benchmark skill to produce a statistically valid Go benchmark and interpret the before/after delta with benchstat for the command you provide.

Frequently Asked Questions about golang-benchmark

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

FAQPage Schema
How do I prevent dead-code elimination from invalidating my Go benchmark results?

Prevent dead-code elimination in Go benchmarks by using Go 1.24+ `b.Loop()` to structure timed code correctly, separating setup from measured operations, and ensuring the compiler cannot optimize away the target execution.

How do I interpret benchstat results when comparing Go performance metrics?

Interpret benchstat results for Go performance by comparing A/B deltas, checking confidence intervals, and recognizing the `~` symbol, which indicates the performance difference is not statistically significant and should not trigger a regression alert.

What flags do I need to run Go benchmarks and generate pprof profiles?

Run Go benchmarks and generate pprof profiles by applying standard flags like `-benchmem` for allocation stats, `-count` for variance estimation, `-benchtime` for duration control, and CPU/memory profile output flags directly to your test command.

When should I use a Go trace workflow versus a CPU pprof profile for diagnosing bottlenecks?

Use a Go trace workflow to diagnose latency, goroutine blocking, and scheduling issues, while selecting CPU pprof profiles to identify flat or cumulative hot spots where the program consumes the most active execution time.

What is the best way to set up CI benchmark regression detection for a Go project?

Set up CI benchmark regression detection for a Go project by integrating tools like benchdiff, cob, or gobenchdata to gate pull requests against baseline measurements and track long-term performance trends with statistical rigor.

Why are my Go benchmark measurements fluctuating and how do I get stable results?

Fluctuating Go benchmark measurements often stem from insufficient sampling or environmental noise; achieve stable results by increasing the `-count` flag to generate enough samples for benchstat to calculate reliable confidence intervals.