diff options
| author | Ondřej Surý <ondrej@sury.org> | 2011-06-03 11:31:24 +0200 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2011-06-03 11:31:24 +0200 |
| commit | 56135c623a865c501ab31cc940c0e22ece2673f4 (patch) | |
| tree | f69e04e82bbf75bdab0f624430ef265425e62b35 /src/pkg/testing/benchmark.go | |
| parent | 63d29fefab5290dc96e0a03ff70603aefa995887 (diff) | |
| download | golang-56135c623a865c501ab31cc940c0e22ece2673f4.tar.gz | |
Imported Upstream version 2011.06.02upstream-weekly/2011.06.02
Diffstat (limited to 'src/pkg/testing/benchmark.go')
| -rw-r--r-- | src/pkg/testing/benchmark.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/pkg/testing/benchmark.go b/src/pkg/testing/benchmark.go index cf73e2b48..db4c65941 100644 --- a/src/pkg/testing/benchmark.go +++ b/src/pkg/testing/benchmark.go @@ -150,7 +150,7 @@ func (b *B) run() BenchmarkResult { type BenchmarkResult struct { N int // The number of iterations. Ns int64 // The total time taken. - Bytes int64 // The total number of bytes processed. + Bytes int64 // Bytes processed in one iteration. } func (r BenchmarkResult) NsPerOp() int64 { @@ -160,13 +160,20 @@ func (r BenchmarkResult) NsPerOp() int64 { return r.Ns / int64(r.N) } +func (r BenchmarkResult) mbPerSec() float64 { + if r.Bytes <= 0 || r.Ns <= 0 || r.N <= 0 { + return 0 + } + return float64(r.Bytes) * float64(r.N) / float64(r.Ns) * 1e3 +} + func (r BenchmarkResult) String() string { - ns := r.NsPerOp() + mbs := r.mbPerSec() mb := "" - if ns > 0 && r.Bytes > 0 { - mb = fmt.Sprintf("\t%7.2f MB/s", (float64(r.Bytes)/1e6)/(float64(ns)/1e9)) + if mbs != 0 { + mb = fmt.Sprintf("\t%7.2f MB/s", mbs) } - return fmt.Sprintf("%8d\t%10d ns/op%s", r.N, ns, mb) + return fmt.Sprintf("%8d\t%10d ns/op%s", r.N, r.NsPerOp(), mb) } // An internal function but exported because it is cross-package; part of the implementation |
