From 0ff876a8505d61fc20f3176f90bc589d76a4c966 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 30 Jun 2017 16:12:28 +0000 Subject: [PATCH] testing: revert CL 36791's conditional ReadMemStats Now that ReadMemStats is fast (CL 34937), CL 36791 is not so necessary, and causes confusion. See #20863 This was already partially reverted in CL 46612 but missed two of the spots. Fixes #20863 Change-Id: I1307a0f7b1f9e86e8b6ceaa6a677f24f13431110 Reviewed-on: https://go-review.googlesource.com/47350 Reviewed-by: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot --- src/testing/benchmark.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go index 484a6d7e12..84005aa322 100644 --- a/src/testing/benchmark.go +++ b/src/testing/benchmark.go @@ -87,11 +87,9 @@ func (b *B) StartTimer() { func (b *B) StopTimer() { if b.timerOn { b.duration += time.Now().Sub(b.start) - if *benchmarkMemory || b.showAllocResult { - runtime.ReadMemStats(&memStats) - b.netAllocs += memStats.Mallocs - b.startAllocs - b.netBytes += memStats.TotalAlloc - b.startBytes - } + runtime.ReadMemStats(&memStats) + b.netAllocs += memStats.Mallocs - b.startAllocs + b.netBytes += memStats.TotalAlloc - b.startBytes b.timerOn = false } } @@ -100,11 +98,9 @@ func (b *B) StopTimer() { // It does not affect whether the timer is running. func (b *B) ResetTimer() { if b.timerOn { - if *benchmarkMemory || b.showAllocResult { - runtime.ReadMemStats(&memStats) - b.startAllocs = memStats.Mallocs - b.startBytes = memStats.TotalAlloc - } + runtime.ReadMemStats(&memStats) + b.startAllocs = memStats.Mallocs + b.startBytes = memStats.TotalAlloc b.start = time.Now() } b.duration = 0 @@ -298,8 +294,6 @@ func (b *B) launch() { } // The results of a benchmark run. -// MemAllocs and MemBytes may be zero if memory benchmarking is not requested -// using B.ReportAllocs or the -benchmem command line flag. type BenchmarkResult struct { N int // The number of iterations. T time.Duration // The total time taken. -- 2.50.0