LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package testing | 5 package testing |
6 | 6 |
7 import ( | 7 import ( |
8 "flag" | 8 "flag" |
9 "fmt" | 9 "fmt" |
10 "os" | 10 "os" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if nsop < 10 { | 249 if nsop < 10 { |
250 ns = fmt.Sprintf("%13.2f ns/op", float64(r.T.Nanoseconds
())/float64(r.N)) | 250 ns = fmt.Sprintf("%13.2f ns/op", float64(r.T.Nanoseconds
())/float64(r.N)) |
251 } else { | 251 } else { |
252 ns = fmt.Sprintf("%12.1f ns/op", float64(r.T.Nanoseconds
())/float64(r.N)) | 252 ns = fmt.Sprintf("%12.1f ns/op", float64(r.T.Nanoseconds
())/float64(r.N)) |
253 } | 253 } |
254 } | 254 } |
255 return fmt.Sprintf("%8d\t%s%s", r.N, ns, mb) | 255 return fmt.Sprintf("%8d\t%s%s", r.N, ns, mb) |
256 } | 256 } |
257 | 257 |
258 func (r BenchmarkResult) MemString() string { | 258 func (r BenchmarkResult) MemString() string { |
259 » return fmt.Sprintf("\t%8d B/op\t%8d allocs/op", | 259 » return fmt.Sprintf("%8d B/op\t%8d allocs/op", |
260 r.AllocedBytesPerOp(), r.AllocsPerOp()) | 260 r.AllocedBytesPerOp(), r.AllocsPerOp()) |
261 } | 261 } |
262 | 262 |
263 // An internal function but exported because it is cross-package; part of the im
plementation | 263 // An internal function but exported because it is cross-package; part of the im
plementation |
264 // of the "go test" command. | 264 // of the "go test" command. |
265 func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [
]InternalBenchmark) { | 265 func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks [
]InternalBenchmark) { |
266 // If no flag was specified, don't run benchmarks. | 266 // If no flag was specified, don't run benchmarks. |
267 if len(*matchBenchmarks) == 0 { | 267 if len(*matchBenchmarks) == 0 { |
268 return | 268 return |
269 } | 269 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // custom benchmarks that do not use the "go test" command. | 336 // custom benchmarks that do not use the "go test" command. |
337 func Benchmark(f func(b *B)) BenchmarkResult { | 337 func Benchmark(f func(b *B)) BenchmarkResult { |
338 b := &B{ | 338 b := &B{ |
339 common: common{ | 339 common: common{ |
340 signal: make(chan interface{}), | 340 signal: make(chan interface{}), |
341 }, | 341 }, |
342 benchmark: InternalBenchmark{"", f}, | 342 benchmark: InternalBenchmark{"", f}, |
343 } | 343 } |
344 return b.run() | 344 return b.run() |
345 } | 345 } |
LEFT | RIGHT |