diff options
| author | Junyang Shao <shaojunyang@google.com> | 2024-11-21 07:36:25 +0000 |
|---|---|---|
| committer | Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-11-21 22:09:32 +0000 |
| commit | 154fb4e1d45e503658542dee5296243a6146e7ca (patch) | |
| tree | 213336d17b34a5ffacf334d4afc34e6934e1c414 /src/testing/benchmark_test.go | |
| parent | 0c6dbd99c570874ef5ec353298708677c1675dd0 (diff) | |
| download | go-154fb4e1d45e503658542dee5296243a6146e7ca.tar.xz | |
testing: Update testing.B.Loop to save benchmark results.
This is fixing some the missing logic of CL 627755.
Change-Id: I35acffef7299331fce21da4a80a26185b2e909f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/630455
Commit-Queue: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/testing/benchmark_test.go')
| -rw-r--r-- | src/testing/benchmark_test.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/testing/benchmark_test.go b/src/testing/benchmark_test.go index 01bb695726..1f55fa5060 100644 --- a/src/testing/benchmark_test.go +++ b/src/testing/benchmark_test.go @@ -127,23 +127,26 @@ func TestRunParallelSkipNow(t *testing.T) { }) } -func TestLoopEqualsRangeOverBN(t *testing.T) { +func TestBLoopHasResults(t *testing.T) { // Verify that b.N and the b.Loop() iteration count match. - var nIterated, nInfered int - testing.Benchmark(func(b *testing.B) { + var nIterated int + bRet := testing.Benchmark(func(b *testing.B) { i := 0 for b.Loop() { i++ } nIterated = i - nInfered = b.N }) - if nIterated != nInfered { - t.Fatalf("Iteration of the two different benchmark loop flavor differs, got %d iterations want %d", nIterated, nInfered) - } if nIterated == 0 { t.Fatalf("Iteration count zero") } + if bRet.N != nIterated { + t.Fatalf("Benchmark result N incorrect, got %d want %d", bRet.N, nIterated) + } + // We only need to check duration to make sure benchmark result is written. + if bRet.T == 0 { + t.Fatalf("Benchmark result duration unset") + } } func ExampleB_RunParallel() { |
