]> Cypherpunks.ru repositories - gostls13.git/commit
testing: only compute b.N once when passed -count > 1
authorAlberto Donizetti <alb.donizetti@gmail.com>
Wed, 2 May 2018 07:45:40 +0000 (09:45 +0200)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Mon, 14 May 2018 17:07:43 +0000 (17:07 +0000)
commit05ca34093bc2d4a367743101ac2a17b697809e75
treee53bfb6bd4d07f204a38f86beb93dcbdde03cb23
parent3c8545c5f6f6db7de1e9c8186fa9f23f4820ad45
testing: only compute b.N once when passed -count > 1

When running a benchmark multiple times, instead of re-computing the
value of b.N each time, use the value found by the first run.

For

  go test -bench=. -benchtime 3s -count 2 p_test.go

on the benchmark in the linked issue; before:

  BenchmarkBenchmark-4         500   10180593 ns/op
  --- BENCH: BenchmarkBenchmark-4
     p_test.go:13: single call took 10.111079ms
     p_test.go:13: single call took 1.017298685s
     p_test.go:13: single call took 5.090096124s
  BenchmarkBenchmark-4         500   10182164 ns/op
  --- BENCH: BenchmarkBenchmark-4
     p_test.go:13: single call took 10.098169ms
     p_test.go:13: single call took 1.017712905s
     p_test.go:13: single call took 5.090898517s
  PASS
  ok   command-line-arguments 12.244s

and after:

  BenchmarkBenchmark-4         500   10177076 ns/op
  --- BENCH: BenchmarkBenchmark-4
     p_test.go:13: single call took 10.091301ms
     p_test.go:13: single call took 1.016943125s
     p_test.go:13: single call took 5.088376028s
  BenchmarkBenchmark-4         500   10171497 ns/op
  --- BENCH: BenchmarkBenchmark-4
     p_test.go:13: single call took 10.140245ms
     p_test.go:13: single call took 5.085605921s
  PASS
  ok   command-line-arguments 11.218s

Fixes #23423

Change-Id: Ie66a8c5ac43881eb8741e14105db28745b4d56d3
Reviewed-on: https://go-review.googlesource.com/110775
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/go_test.go
src/testing/benchmark.go