go-turbo-benchlisted
Install: claude install-skill hendriknielaender/go-turbo
# go-turbo-bench
Write the benchmark, run it properly, read it honestly.
Most Go benchmarks measure something other than what their author intended, in
four classic ways: the compiler deleted the work, setup got timed, the input was
unrepresentative, or one run was compared against one run and noise was reported
as a win. Guarding against those is most of this job.
## Writing
```go
func BenchmarkParse(b *testing.B) {
input := loadTestData() // setup outside the timed region
b.ReportAllocs()
for b.Loop() { // Go 1.24+
_ = Parse(input)
}
}
```
`b.Loop()` keeps the loop body's results live (no dead-code elimination) and
excludes setup automatically. On older Go, use `b.N` with a package-level sink
and `b.ResetTimer()`:
```go
var sink Result
func BenchmarkParse(b *testing.B) {
input := loadTestData()
b.ReportAllocs()
b.ResetTimer()
var r Result
for i := 0; i < b.N; i++ {
r = Parse(input)
}
sink = r
}
```
**Always `b.ReportAllocs()`.** B/op and allocs/op are near-deterministic and
usually explain the ns/op movement; ns/op alone drifts with machine load.
**Cover the input distribution**, not one convenient case:
```go
func BenchmarkParse(b *testing.B) {
for _, size := range []int{1 << 10, 64 << 10, 1 << 20} {
b.Run(fmt.Sprintf("size=%d", size), func(b *testing.B) {
input := makeInput(size)
b.ReportAllocs()
b.SetBytes(int64(size)) // adds MB/s