← All notes

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

Sources

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

Permanent ID: iil:note:br5y91zd

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.},
}

Markdown

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.

All artifact files (JSON index)

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.