aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/benchmark.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go
index 0271308346..2c7083db02 100644
--- a/src/testing/benchmark.go
+++ b/src/testing/benchmark.go
@@ -114,6 +114,7 @@ type B struct {
// Extra metrics collected by ReportMetric.
extra map[string]float64
// Remaining iterations of Loop() to be executed in benchFunc.
+ // See issue #61515.
loopN int
}
@@ -358,6 +359,11 @@ func (b *B) ReportMetric(n float64, unit string) {
// After the benchmark finishes, b.N will contain the total number of calls to op, so the benchmark
// may use b.N to compute other average metrics.
func (b *B) Loop() bool {
+ if b.loopN == b.N {
+ // If it's the first call to b.Loop() in the benchmark function.
+ // Allows more precise measurement of benchmark loop cost counts.
+ b.ResetTimer()
+ }
b.loopN--
return b.loopN >= 0
}