skip to content
Alvin Lucillo

Control benchmark run duration

/ 1 min read

Instead of -count=10, we can pass a specific duration a benchmark should run with benchtime:

go test -run '^$' -bench '^BenchmarkEncode$/^format=binary$' \
  -benchtime=5s
goos: linux
goarch: arm64
pkg: codec01
BenchmarkEncode/format=binary-12                195745051               30.57 ns/op     1603.04 MB/s          64 B/op          1 allocs/op
PASS
ok      codec01 5.989s