# CPU/Data Structures Experiment Loop — Go

Extends `../shared/experiment-loop-base.md` with Go CPU-specific steps.

## Domain-Specific Additions

**Step 1 — Baseline profiling**: Run `go test -bench=. -cpuprofile=/tmp/cpu.prof -benchmem -count=5` and save benchmark output to `/tmp/bench_baseline.txt`. Extract ranked targets with `go tool pprof -top -cum`.

**Step 3 — Reasoning checklist**: Use the 9-question checklist from `codeflash-cpu.md`.

**Step 5 — Micro-benchmark**: Write a targeted benchmark in `_test.go` if one doesn't exist for the target function.

**Step 9 — Benchmark**: Run `go test -bench=BenchmarkTarget -benchmem -count=5` and compare with `benchstat /tmp/bench_baseline.txt /tmp/bench_after.txt`.

**Step 10 — Guard**: Default guard for Go: `go test -race -short ./...`.

**Step 12 — Re-profile (after KEEP)**: Re-run `go test -cpuprofile` and `go tool pprof -top -cum` to get fresh rankings. Update baseline: `cp /tmp/bench_after.txt /tmp/bench_baseline.txt`.

## Keep Thresholds

- **ns/op**: ≥5% improvement with p < 0.05
- **Micro-benchmark only**: ≥20% improvement on confirmed hot path
- **allocs/op side effect**: Any reduction is a bonus, not required for CPU domain

## Plateau

- All remaining hotspots below 2% of original baseline cumtime
- 3+ consecutive discards
- Remaining hotspots in runtime, stdlib, or CGo
