1
0
mirror of https://github.com/golang/go synced 2024-11-21 21:34:40 -07:00

testing: run GC before each benchmark run.

R=r, rh, gri, rsc
CC=golang-dev
https://golang.org/cl/4237055
This commit is contained in:
Roger Peppe 2011-03-03 11:26:53 -08:00 committed by Rob Pike
parent 5bd284e868
commit da833474f5

View File

@ -8,6 +8,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"os" "os"
"runtime"
"time" "time"
) )
@ -64,6 +65,9 @@ func (b *B) nsPerOp() int64 {
// runN runs a single benchmark for the specified number of iterations. // runN runs a single benchmark for the specified number of iterations.
func (b *B) runN(n int) { 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.N = n
b.ResetTimer() b.ResetTimer()
b.StartTimer() b.StartTimer()