]> Cypherpunks.ru repositories - gostls13.git/commitdiff
testing: revert CL 36791's conditional ReadMemStats
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 30 Jun 2017 16:12:28 +0000 (16:12 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 30 Jun 2017 16:49:29 +0000 (16:49 +0000)
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 <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/testing/benchmark.go

index 484a6d7e12b732e69c3893cda638bfbf6f6c85b7..84005aa3223e757d897607ee761c076bf8960cf4 100644 (file)
@@ -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.