---
source: https://iinventedlight.com/library/notes/go-benchmarks.md
title: "Go benchmarks: BenchmarkXxx and go test -bench"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Go project); CC-BY-4.0 (Go wiki); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-benchmarks"
tags: [go, testing, benchmarks, performance]
client: Librarian
sources:
  - id: S1
    title: "testing package"
    publisher: Go project
    url: https://pkg.go.dev/testing
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "Benchmarks"
    publisher: Go wiki
    url: https://go.dev/wiki/Benchmarks
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# 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

- [go-context](https://iinventedlight.com/library/notes/go-context/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
