Agent skill
benchmarking
Go benchmarking for measuring and optimising code performance
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/benchmarking-baphled-dotopencode
SKILL.md
Skill: benchmarking
What I do
I provide Go-specific benchmarking expertise to measure and optimise code performance. I focus on writing reliable benchmarks using the testing package and analysing results to identify bottlenecks.
When to use me
- When comparing the performance of multiple implementations
- When verifying the impact of an optimisation
- When identifying hotspots in performance-critical code paths
Core principles
- Isolation: Run benchmarks in a stable environment to minimise noise.
- Reliability: Use
b.ResetTimer()to exclude setup overhead andb.ReportAllocs()to track memory allocations. - Statistical significance: Use tools like
benchstatto compare results across multiple runs. - Realistic data: Use representative input sizes to avoid misleading results from small or trivial datasets.
Patterns & examples
Standard benchmark function:
func BenchmarkProcessData(b *testing.B) {
data := setupTestData()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ProcessData(data)
}
}
Table-driven benchmark:
func BenchmarkAlgorithm(b *testing.B) {
benchmarks := []struct {
name string
size int
}{
{"Small", 10},
{"Medium", 100},
{"Large", 1000},
}
for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
data := generateData(bm.size)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Algorithm(data)
}
})
}
}
Comparing results:
Use go test -bench . -count 5 > old.txt and go test -bench . -count 5 > new.txt, then run benchstat old.txt new.txt to see the percentage change.
Anti-patterns to avoid
- ❌ Looping manually: Always use
b.Nfor the loop count. Hardcoding iterations leads to unreliable timing. - ❌ Compiler optimisations: Ensure the result of the function under test is used (e.g., assigned to a package-level variable) to prevent the compiler from eliding the call.
- ❌ Ignoring allocations: High memory allocation counts often indicate performance issues that timing alone might miss.
KB Reference
~/vaults/baphled/3. Resources/Knowledge Base/AI Development System/Skills/Performance-Profiling/Benchmarking.md
Related skills
profiling: For deep dives into where time or memory is spentperformance: General optimisation principles and techniquesgolang: For idiomatic Go patterns and standard library usage
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?