Go benchmarks: BenchmarkXxx and go test -bench
Answer: Functions of the form func BenchmarkXxx(*testing.B) are considered benchmarks. The go test command executes them when its -bench flag is provided. Wiki benchmarks also run under go test -bench.
Writing a benchmark
Functions of the form func BenchmarkXxx(*testing.B) are considered benchmarks.
Provide the -bench flag to go test and those functions are executed.
Benchmarks are run sequentially.
A sample benchmark function looks like this, using for b.Loop().
Community benchmark list
The wiki collects community benchmarks used to measure the effects of changes to the Go core.
Listed benchmarks should be go-gettable, and they run under go test -bench.
A single run should ideally take less than a second, so the suite stays relatively quick.
See also
Claims
- id: C1 claim: Functions named BenchmarkXxx(testing.B) are considered benchmarks. source: S1 evidence: "func BenchmarkXxx(testing.B) are considered benchmarks"
- id: C2 claim: go test executes them when the -bench flag is provided. source: S1 evidence: "when its -bench flag is provided"
- id: C3 claim: Benchmarks are run sequentially. source: S1 evidence: "Benchmarks are run sequentially"
- id: C4 claim: Wiki benchmarks are expected to run under go test -bench. source: S2 evidence: "they run under go test -bench"
Sources
- [S1] testing package. Go project. https://pkg.go.dev/testing . License: CC-BY-4.0. Accessed 2026-11-23.
- [S2] Benchmarks. Go wiki. https://go.dev/wiki/Benchmarks . License: CC-BY-4.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go project, testing package; Go wiki, Benchmarks. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go project, testing package; Go wiki, Benchmarks. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go benchmarks: BenchmarkXxx and go test -bench." iinventedlight Library, iil:note:br5y91zd, version of 2026-11-23. https://iinventedlight.com/library/notes/go-benchmarks/. License: CC-BY-4.0.
@misc{iil_note_br5y91zd,
author = {{iinventedlight}},
title = {{Go benchmarks: BenchmarkXxx and go test -bench}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-benchmarks/},
note = {Permanent ID iil:note:br5y91zd. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-benchmarks.schema.json (schema; CC-BY-4.0)
- go-benchmarks.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-benchmarks.md.