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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // An internal function but exported because it is cross-package; part of the im
plementation | 168 // An internal function but exported because it is cross-package; part of the im
plementation |
169 // of gotest. | 169 // of gotest. |
170 func RunBenchmarks(matchString func(pat, str string) (bool, os.Error), benchmark
s []InternalBenchmark) { | 170 func RunBenchmarks(matchString func(pat, str string) (bool, os.Error), benchmark
s []InternalBenchmark) { |
171 // If no flag was specified, don't run benchmarks. | 171 // If no flag was specified, don't run benchmarks. |
172 if len(*matchBenchmarks) == 0 { | 172 if len(*matchBenchmarks) == 0 { |
173 return | 173 return |
174 } | 174 } |
175 for _, Benchmark := range benchmarks { | 175 for _, Benchmark := range benchmarks { |
176 matched, err := matchString(*matchBenchmarks, Benchmark.Name) | 176 matched, err := matchString(*matchBenchmarks, Benchmark.Name) |
177 if err != nil { | 177 if err != nil { |
178 » » » println("invalid regexp for -benchmarks:", err) | 178 » » » println("invalid regexp for -benchmarks:", err.String()) |
179 os.Exit(1) | 179 os.Exit(1) |
180 } | 180 } |
181 if !matched { | 181 if !matched { |
182 continue | 182 continue |
183 } | 183 } |
184 b := &B{benchmark: Benchmark} | 184 b := &B{benchmark: Benchmark} |
185 r := b.run() | 185 r := b.run() |
186 fmt.Printf("%s\t%v\n", Benchmark.Name, r) | 186 fmt.Printf("%s\t%v\n", Benchmark.Name, r) |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 // Benchmark benchmarks a single function. Useful for creating | 190 // Benchmark benchmarks a single function. Useful for creating |
191 // custom benchmarks that do not use gotest. | 191 // custom benchmarks that do not use gotest. |
192 func Benchmark(f func(b *B)) BenchmarkResult { | 192 func Benchmark(f func(b *B)) BenchmarkResult { |
193 b := &B{benchmark: InternalBenchmark{"", f}} | 193 b := &B{benchmark: InternalBenchmark{"", f}} |
194 return b.run() | 194 return b.run() |
195 } | 195 } |
LEFT | RIGHT |