1
0
mirror of https://github.com/golang/go synced 2024-11-25 03:57:56 -07:00

testing: scale benchmark precision to 0.01ns if needed

R=dvyukov, r
CC=golang-dev
https://golang.org/cl/4657053
This commit is contained in:
Russ Cox 2011-06-27 18:50:27 -04:00
parent 6aaa86ff66
commit 8475832f0d

View File

@ -174,7 +174,18 @@ func (r BenchmarkResult) String() string {
if mbs != 0 {
mb = fmt.Sprintf("\t%7.2f MB/s", mbs)
}
return fmt.Sprintf("%8d\t%10d ns/op%s", r.N, r.NsPerOp(), mb)
nsop := r.NsPerOp()
ns := fmt.Sprintf("%10d ns/op", nsop)
if r.N > 0 && nsop < 100 {
// The format specifiers here make sure that
// the ones digits line up for all three possible formats.
if nsop < 10 {
ns = fmt.Sprintf("%13.2f ns/op", float64(r.Ns)/float64(r.N))
} else {
ns = fmt.Sprintf("%12.1f ns/op", float64(r.Ns)/float64(r.N))
}
}
return fmt.Sprintf("%8d\t%s%s", r.N, ns, mb)
}
// An internal function but exported because it is cross-package; part of the implementation