go-benchmark
Write and analyze Go benchmarks using modern patterns and tools
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Menu
Write and analyze Go benchmarks using modern patterns and tools
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Basé sur la classification professionnelle SOC
Best practices for working with Go codebases. Use when writing, debugging, or exploring Go code, including reading dependency sources and documentation.
Autonomous orchestration loop for hive hc tasks. The high-capability manager model reads pending tasks, delegates implementation to cheaper worker sub-agents, critically reviews their output, and commits only code that passes quality checks. Runs to completion without stopping to ask questions.
Post-implementation design re-evaluation. After a feature reaches a working state through iteration, step back and re-examine what actually got built: are the data structures and algorithms the right fit for the access patterns that emerged, can code paths that grew through iteration be consolidated, and what iteration residue (tests for abandoned designs, dead flags/scaffolding, debug logging) should be deleted. Produces a tiered proposal report and applies only approved changes. Use when the user says "rethink this", "step back and re-evaluate", "is this the right design/data structure", "apply CS fundamentals", or wants a design pass on a working feature branch before PR. Not for bug-hunting (/review) or expression-level polish (/simplify) — this questions the design those skills preserve.
Orchestrate parallel claude and codex CLI agents through tmux to deliver a feature end-to-end. The orchestrator delegates planning, work, and review to spawned agents in tmux windows; it does NOT write or edit code itself. User-invoked only.
Open the current branch's diff (or a specific PR) in Plannotator's browser-based code review UI and act on the returned feedback. Use when the user says "review my changes in plannotator", "open the diff for review", "review this PR in plannotator", "let me annotate the diff", or returns to a session to gate code the agent produced.
Single-pass code review of the current branch (or a diff) that routes the changes to relevant concerns, dispatches fresh-context reviewer sub-agents, verifies findings to strip false positives, and reports a ranked, evidence-backed review. Use when the user asks to review local changes, a branch, or a PR before it goes to humans.
| name | go-benchmark |
| description | Write and analyze Go benchmarks using modern patterns and tools |
| argument-hint | ["benchmark-task"] |
| disable-model-invocation | true |
Write effective Go benchmarks using the new Loop pattern and analyze results with benchstat.
Use b.Loop() instead of explicit for i := 0; i < b.N; i++ loops:
func BenchmarkExample(b *testing.B) {
// Setup - not measured
data := generateTestData()
for b.Loop() {
// Code to measure
result := processData(data)
_ = result // Keep result alive
}
// Cleanup - not measured
}
b.Loop() - variations don't workPhilosophy: Make small changes, measure each change, understand impact before proceeding.
go test -bench=. -count=10 > old.txtgo test -bench=. -count=10 > new.txtbenchstat old.txt new.txtNever change multiple things at once - you won't know which change caused the impact.
Install: go install golang.org/x/perf/cmd/benchstat@latest
# Run old version
go test -bench=BenchmarkProcess -count=10 > old.txt
# Make changes, run new version
go test -bench=BenchmarkProcess -count=10 > new.txt
# Compare with statistical significance
benchstat old.txt new.txt
name old time/op new time/op delta
Process-8 1.23µs ± 2% 0.98µs ± 1% -20.33% (p=0.000 n=10+10)
± indicates variance (lower is more stable)delta shows percentage changep value indicates statistical significance (< 0.05 is significant)n shows sample sizeIgnore changes under 5% - measurement noise is real.
// BAD: Result not used, entire loop may be optimized away
for b.Loop() {
processData(data)
}
// GOOD: Assign to package-level var
var result int
for b.Loop() {
result = processData(data)
}
// GOOD: Use within loop body (Loop keeps it alive)
for b.Loop() {
r := processData(data)
_ = r
}
func BenchmarkAllocations(b *testing.B) {
b.ReportAllocs() // Include allocation stats in output
for b.Loop() {
data := make([]byte, 1024) // Measure this allocation
_ = data
}
}
Look for allocs/op in output - reducing allocations often improves performance more than CPU optimization.
func BenchmarkEncode(b *testing.B) {
sizes := []int{1, 10, 100, 1000}
for _, size := range sizes {
b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) {
data := make([]byte, size)
for b.Loop() {
encode(data)
}
})
}
}
Run specific sub-benchmark: go test -bench=BenchmarkEncode/size=100
// BAD: Manual timer management is error-prone
for b.Loop() {
b.StopTimer()
setup := prepareData()
b.StartTimer()
process(setup)
}
// GOOD: Move setup outside loop
for b.Loop() {
setup := prepareData()
process(setup)
}
// BEST: If setup must be per-iteration, benchmark it separately
Loop handles timer automatically - manual control usually indicates wrong benchmark structure.
func BenchmarkParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() { // Use pb.Next() not b.Loop() in parallel
doWork()
}
})
}
Note: RunParallel uses pb.Next() not b.Loop() - different API for concurrent execution.
func BenchmarkHandler(b *testing.B) {
handler := NewHandler()
req := httptest.NewRequest("GET", "/api/data", nil)
for b.Loop() {
w := httptest.NewRecorder()
handler.ServeHTTP(w, req)
}
}
func BenchmarkQuery(b *testing.B) {
db := setupTestDB(b)
defer db.Close()
b.ResetTimer() // Don't measure setup
for b.Loop() {
rows, err := db.Query("SELECT * FROM users WHERE age > ?", 18)
if err != nil {
b.Fatal(err)
}
rows.Close()
}
}
func BenchmarkHash(b *testing.B) {
cases := []struct {
name string
size int
}{
{"small", 16},
{"medium", 1024},
{"large", 65536},
}
for _, tc := range cases {
b.Run(tc.name, func(b *testing.B) {
data := make([]byte, tc.size)
for b.Loop() {
hash(data)
}
})
}
}
# All benchmarks in package
go test -bench=.
# Specific benchmark
go test -bench=BenchmarkEncode
# With memory allocations
go test -bench=. -benchmem
# Multiple runs for stability
go test -bench=. -count=10
# Longer runs for accuracy
go test -bench=. -benchtime=10s
# CPU profiling
go test -bench=. -cpuprofile=cpu.prof
# Memory profiling
go test -bench=. -memprofile=mem.prof
go test -bench=BenchmarkProcess -cpuprofile=cpu.prof
go tool pprof cpu.prof
# Then: top, list FunctionName, web
go test -bench=BenchmarkProcess -memprofile=mem.prof
go tool pprof -alloc_space mem.prof
# Run baseline
go test -bench=. -count=10 > baseline.txt
# After change 1
go test -bench=. -count=10 > change1.txt
benchstat baseline.txt change1.txt
# After change 2
go test -bench=. -count=10 > change2.txt
benchstat baseline.txt change2.txt
# Compare all three
benchstat baseline.txt change1.txt change2.txt
Unstable results (high variance):
-count to get more samples-cpu=1 to reduce scheduling effectsResults too good to be true:
-gcflags='-m' to see optimization decisionsInconsistent improvements:
-count=20)-benchtime=5s for longer, more stable runsfor i := 0; i < b.N loopsb.ReportAllocs() often finds easy wins_ to prevent dead code elimination-count=10 minimum for reliable comparisonWhen /go-benchmark is invoked:
b.Loop() patternb.ReportAllocs() if allocations matter_ =)-count=10 for baselinebenchstat