Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(424)

Side by Side Diff: src/pkg/testing/benchmark.go

Issue 12405043: code review 12405043: testing: add Frames method to adjust the logging of the... (Closed)
Patch Set: diff -r bf1cd157b3e0 https://code.google.com/p/go Created 10 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pkg/testing/testing.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/testing/testing.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b