]> Cypherpunks repositories - gostls13.git/commitdiff
testing: run GC before each benchmark run.
authorRoger Peppe <rogpeppe@gmail.com>
Thu, 3 Mar 2011 19:26:53 +0000 (11:26 -0800)
committerRob Pike <r@golang.org>
Thu, 3 Mar 2011 19:26:53 +0000 (11:26 -0800)
R=r, rh, gri, rsc
CC=golang-dev
https://golang.org/cl/4237055

src/pkg/testing/benchmark.go

index 8c226c4d41196c36f05bf06a4a597cd8db245634..cf73e2b48f8ece11cb114807436869f6a8c1070e 100644 (file)
@@ -8,6 +8,7 @@ import (
        "flag"
        "fmt"
        "os"
+       "runtime"
        "time"
 )
 
@@ -64,6 +65,9 @@ func (b *B) nsPerOp() int64 {
 
 // runN runs a single benchmark for the specified number of iterations.
 func (b *B) runN(n int) {
+       // Try to get a comparable environment for each run
+       // by clearing garbage from previous runs.
+       runtime.GC()
        b.N = n
        b.ResetTimer()
        b.StartTimer()