OLD | NEW |
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 16 matching lines...) Expand all Loading... |
27 // of the "go test" command. | 27 // of the "go test" command. |
28 type InternalBenchmark struct { | 28 type InternalBenchmark struct { |
29 Name string | 29 Name string |
30 F func(b *B) | 30 F func(b *B) |
31 } | 31 } |
32 | 32 |
33 // B is a type passed to Benchmark functions to manage benchmark | 33 // B is a type passed to Benchmark functions to manage benchmark |
34 // timing and to specify the number of iterations to run. | 34 // timing and to specify the number of iterations to run. |
35 type B struct { | 35 type B struct { |
36 common | 36 common |
| 37 logger |
37 N int | 38 N int |
38 benchmark InternalBenchmark | 39 benchmark InternalBenchmark |
39 bytes int64 | 40 bytes int64 |
40 timerOn bool | 41 timerOn bool |
41 showAllocResult bool | 42 showAllocResult bool |
42 result BenchmarkResult | 43 result BenchmarkResult |
43 // The initial states of memStats.Mallocs and memStats.TotalAlloc. | 44 // The initial states of memStats.Mallocs and memStats.TotalAlloc. |
44 startAllocs uint64 | 45 startAllocs uint64 |
45 startBytes uint64 | 46 startBytes uint64 |
46 // The net total of this test after being run. | 47 // The net total of this test after being run. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 287 } |
287 if !matched { | 288 if !matched { |
288 continue | 289 continue |
289 } | 290 } |
290 for _, procs := range cpuList { | 291 for _, procs := range cpuList { |
291 runtime.GOMAXPROCS(procs) | 292 runtime.GOMAXPROCS(procs) |
292 b := &B{ | 293 b := &B{ |
293 common: common{ | 294 common: common{ |
294 signal: make(chan interface{}), | 295 signal: make(chan interface{}), |
295 }, | 296 }, |
| 297 logger: logger{ |
| 298 frames: 3, // decorate + log + public fu
nction. |
| 299 }, |
296 benchmark: Benchmark, | 300 benchmark: Benchmark, |
297 } | 301 } |
298 benchName := Benchmark.Name | 302 benchName := Benchmark.Name |
| 303 b.logger.common = &b.common |
299 if procs != 1 { | 304 if procs != 1 { |
300 benchName = fmt.Sprintf("%s-%d", Benchmark.Name,
procs) | 305 benchName = fmt.Sprintf("%s-%d", Benchmark.Name,
procs) |
301 } | 306 } |
302 fmt.Printf("%s\t", benchName) | 307 fmt.Printf("%s\t", benchName) |
303 r := b.run() | 308 r := b.run() |
304 if b.failed { | 309 if b.failed { |
305 // The output could be very long here, but proba
bly isn't. | 310 // The output could be very long here, but proba
bly isn't. |
306 // We print it all, regardless, because we don't
want to trim the reason | 311 // We print it all, regardless, because we don't
want to trim the reason |
307 // the benchmark failed. | 312 // the benchmark failed. |
308 fmt.Printf("--- FAIL: %s\n%s", benchName, b.outp
ut) | 313 fmt.Printf("--- FAIL: %s\n%s", benchName, b.outp
ut) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 // custom benchmarks that do not use the "go test" command. | 352 // custom benchmarks that do not use the "go test" command. |
348 func Benchmark(f func(b *B)) BenchmarkResult { | 353 func Benchmark(f func(b *B)) BenchmarkResult { |
349 b := &B{ | 354 b := &B{ |
350 common: common{ | 355 common: common{ |
351 signal: make(chan interface{}), | 356 signal: make(chan interface{}), |
352 }, | 357 }, |
353 benchmark: InternalBenchmark{"", f}, | 358 benchmark: InternalBenchmark{"", f}, |
354 } | 359 } |
355 return b.run() | 360 return b.run() |
356 } | 361 } |
OLD | NEW |