Closed
Description
Currently benchmarks built using testing
's Benchmark
interface run a variable number of iterations, auto-adjusting to run for at least -benchiters
seconds. This complicates HW PMU counter collection and A/B comparisons because the amount of work is (potentially) variable and the time adjustment code can muddle the benchmark results. It can also easily overshoot the amount of time you expect it to take:
$ go test archive/zip -benchtime 30s -run=Benchmark -bench=BenchmarkZip64Test$
goos: linux
goarch: amd64
pkg: archive/zip
BenchmarkZip64Test-8 1000 59382178 ns/op
PASS
ok archive/zip 65.380s
The proposal
is to add a new flag to go test
that circumvents the adjustment process and runs a benchmark for some exact user-defined number of iterations:
$ go test archive/zip -benchiterations 500 -run=Benchmark -bench=BenchmarkZip64Test$
goos: linux
goarch: amd64
pkg: archive/zip
BenchmarkZip64Test-8 500 59419401 ns/op
PASS
ok archive/zip 29.775s
References
A draft of this change is already on Gerrit (+92617)