# Benchmark

> Create or modify hot-path code or optimizations should be validated by a Go Benchmark

- Skill: `zalando/benchmark` (Agent Skill)
- Install (CLI): `npx skillmds@latest add zalando/benchmark`
- Raw SKILL.md: https://api.skillmd.com/api/skills/zalando/benchmark/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: MIT
- Author: zalando (https://skillmd.com/u/zalando)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/zalando/benchmark

---

## What I do

- focus on performance and allocations

## When to use me

Use this when you are creating or modifying code in the hot path.

## Quick start

### Benchmarks

Write benchmarks alongside any performance-sensitive change. Use `benchstat`
with `-count 20` to compare. Always report `sec/op`, `B/op`, and `allocs/op`.
Target zero allocations in hot-path code.

```go
func BenchmarkMyPredicate(b *testing.B) {
    p := &predicate{...}
    req := httptest.NewRequest("GET", "/", nil)
    req.Header.Set("Authorization", "Bearer "+testToken)
    b.ReportAllocs()
    b.ResetTimer()
    for b.Loop() {
        p.Match(req)
    }
}
```

Example run:

```bash
% go test -bench=BenchmarkMyPredicate -benchmem -run='^$' -count 20 -cpu 1,2,4,8,16 ./predicates/mypredicate > old.txt
# ..edit code..
% go test -bench=BenchmarkMyPredicate -benchmem -run='^$' -count 20 -cpu 1,2,4,8,16 ./predicates/mypredicate > new.txt
% benchstat old.txt new.txt
```

Show the output of benchstat to the developer.

