From 709b18186985c2ae7b6b5eb9cded2c635aa74be5 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Sun, 19 Jul 2026 22:59:29 +0200 Subject: [PATCH] docs(golang-benchmark): correct rationale for separate _bench_test.go files (#83) The file-separation rationale claimed that splitting benchmarks out of `parser_test.go` lets `go test -run . -short` skip "compiling benchmark-only fixtures". That is not how the Go toolchain works: all `*_test.go` files in a package are compiled into a single test binary regardless of `-run`, `-bench` or `-short`. Replace the claim with the two rationales that actually hold: cleaner `-bench` output, and separation of measurement-sized fixtures from correctness-sized ones. --- skills/golang-benchmark/SKILL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skills/golang-benchmark/SKILL.md b/skills/golang-benchmark/SKILL.md index 91a93cc..7a3a6f3 100644 --- a/skills/golang-benchmark/SKILL.md +++ b/skills/golang-benchmark/SKILL.md @@ -6,7 +6,7 @@ license: MIT compatibility: Designed for Claude Code or similar AI coding agents, and for projects using Golang. metadata: author: samber - version: "1.2.6" + version: "1.2.7" openclaw: emoji: "📊" homepage: https://github.com/samber/cc-skills-golang @@ -39,7 +39,7 @@ This skill covers the full measurement workflow: write a benchmark, run it, prof ### File and Ordering Conventions -Benchmark functions live in a `_bench_test.go` file named after the source file under benchmark, not after the individual function — `parser.go` -> `parser_bench_test.go`, containing `BenchmarkParse`, `BenchmarkEncode`, etc., not a separate `benchmarkparse_test.go` per function. Keeping benchmarks in their own file (instead of mixed into `parser_test.go`) lets `go test -run . -short` skip the package's regular test run without also compiling benchmark-only fixtures, and keeps `go test -bench=. ./pkg/parser` output free of unrelated `Test*` noise. The file still follows Go's one-test-file-per-source-file convention (→ See `samber/cc-skills-golang@golang-testing` skill), just with the `_bench` suffix marking its narrower purpose. +Benchmark functions live in a `_bench_test.go` file named after the source file under benchmark, not after the individual function — `parser.go` -> `parser_bench_test.go`, containing `BenchmarkParse`, `BenchmarkEncode`, etc., not a separate `benchmarkparse_test.go` per function. Keeping benchmarks in their own file (instead of mixed into `parser_test.go`) keeps `go test -bench=. ./pkg/parser` output free of unrelated `Test*` noise, and separates fixtures sized for measurement (large inputs, long-lived setup) from those sized for correctness — the two rarely share the same shape. The file still follows Go's one-test-file-per-source-file convention (→ See `samber/cc-skills-golang@golang-testing` skill), just with the `_bench` suffix marking its narrower purpose. Order `Benchmark*` functions inside `parser_bench_test.go` to mirror the order of the functions/methods they measure in `parser.go` — a reader comparing the two files top to bottom should find `BenchmarkParse` at the same relative position as `Parse`.