Hello r, I'd like you to review the following change.
LGTM On Dec 4, 2009, at 9:34 AM, rsc@golang.org wrote: > Reviewers: r, > > Message: > Hello r, > > I'd like you to review the following change. > > > Description: > testing: compute MB/s in benchmarks > > Please review this at http://codereview.appspot.com/166060 > > Affected files: > M src/pkg/testing/benchmark.go > > > Index: src/pkg/testing/benchmark.go > =================================================================== > --- a/src/pkg/testing/benchmark.go > +++ b/src/pkg/testing/benchmark.go > @@ -26,6 +26,7 @@ > N int; > benchmark Benchmark; > ns int64; > + bytes int64; > start int64; > } > > @@ -50,6 +51,10 @@ > b.ns = 0; > } > > +// SetBytes records the number of bytes processed in a single operation. > +// If this is called, the benchmark will report ns/op and MB/s. > +func (b *B) SetBytes(n int64) { b.bytes = n } > + > func (b *B) nsPerOp() int64 { > if b.N <= 0 { > return 0 > @@ -125,7 +130,12 @@ > n = roundUp(n); > b.runN(n); > } > - fmt.Printf("%s\t%d\t%10d ns/op\n", b.benchmark.Name, b.N, b.nsPerOp()); > + ns := b.nsPerOp(); > + mb := ""; > + if ns > 0 && b.bytes > 0 { > + mb = fmt.Sprintf("\t%7.2f MB/s", (float64(b.bytes)/1e6)/(float64(ns)/1e9)) > + } > + fmt.Printf("%s\t%8d\t%10d ns/op%s\n", b.benchmark.Name, b.N, b.nsPerOp(), mb); > } > > // An internal function but exported because it is cross-package; part of the implementation > >
*** Submitted as http://code.google.com/p/go/source/detail?r=8db2fdef9145 *** testing: compute MB/s in benchmarks R=r http://codereview.appspot.com/166060