Commit f8b58381 authored by David Symonds's avatar David Symonds

testing: change -test.benchtime to a flag.Duration.

Fixes #3902.

R=golang-dev, minux.ma, rsc, r
CC=golang-dev
https://golang.org/cl/6611059
parent 05e4e805
......@@ -88,7 +88,7 @@ __go_tool_complete() {
"-cpu[values of GOMAXPROCS to use]:number list" \
"-run[run tests and examples matching regexp]:regexp" \
"-bench[run benchmarks matching regexp]:regexp" \
"-benchtime[run each benchmark during n seconds]:duration" \
"-benchtime[run each benchmark until taking this long]:duration" \
"-timeout[kill test after that duration]:duration" \
"-cpuprofile[write CPU profile to file]:file:_files" \
"-memprofile[write heap profile to file]:file:_files" \
......
......@@ -708,8 +708,8 @@ directory containing the package sources, has its own flags:
-test.timeout t
If a test runs longer than t, panic.
-test.benchtime n
Run enough iterations of each benchmark to take n seconds.
-test.benchtime t
Run enough iterations of each benchmark to take t.
The default is 1 second.
-test.cpu 1,2,4
......
......@@ -138,8 +138,8 @@ directory containing the package sources, has its own flags:
-test.timeout t
If a test runs longer than t, panic.
-test.benchtime n
Run enough iterations of each benchmark to take n seconds.
-test.benchtime t
Run enough iterations of each benchmark to take t.
The default is 1 second.
-test.cpu 1,2,4
......
......@@ -26,7 +26,7 @@ var usageMessage = `Usage of go test:
// These flags can be passed with or without a "test." prefix: -v or -test.v.
-bench="": passes -test.bench to test
-benchmem=false: print memory allocation statistics for benchmarks
-benchtime=1: passes -test.benchtime to test
-benchtime=1s: passes -test.benchtime to test
-cpu="": passes -test.cpu to test
-cpuprofile="": passes -test.cpuprofile to test
-memprofile="": passes -test.memprofile to test
......
......@@ -13,7 +13,7 @@ import (
)
var matchBenchmarks = flag.String("test.bench", "", "regular expression to select benchmarks to run")
var benchTime = flag.Float64("test.benchtime", 1, "approximate run time for each benchmark, in seconds")
var benchTime = flag.Duration("test.benchtime", 1*time.Second, "approximate run time for each benchmark")
// An internal type but exported because it is cross-package; part of the implementation
// of go test.
......@@ -151,7 +151,7 @@ func (b *B) launch() {
b.runN(n)
// Run the benchmark for at least the specified amount of time.
d := time.Duration(*benchTime * float64(time.Second))
d := *benchTime
for !b.failed && b.duration < d && n < 1e9 {
last := n
// Predict iterations/sec.
......
......@@ -45,7 +45,7 @@ VARIABLES
)
//
var benchTime = flag.Float64("test.benchtime", 1, "approximate run time for each benchmark, in seconds")
var benchTime = flag.Duration("test.benchtime", 1*time.Second, "approximate run time for each benchmark")
//
var matchBenchmarks = flag.String("test.bench", "", "regular expression to select benchmarks to run")
......
......@@ -1378,7 +1378,7 @@ func benchmarkClientServerParallel(b *testing.B, conc int) {
//
// For use like:
// $ go test -c
// $ ./http.test -test.run=XX -test.bench=BenchmarkServer -test.benchtime=15 -test.cpuprofile=http.prof
// $ ./http.test -test.run=XX -test.bench=BenchmarkServer -test.benchtime=15s -test.cpuprofile=http.prof
// $ go tool pprof http.test http.prof
// (pprof) web
func BenchmarkServer(b *testing.B) {
......
......@@ -14,7 +14,7 @@ import (
)
var matchBenchmarks = flag.String("test.bench", "", "regular expression to select benchmarks to run")
var benchTime = flag.Float64("test.benchtime", 1, "approximate run time for each benchmark, in seconds")
var benchTime = flag.Duration("test.benchtime", 1*time.Second, "approximate run time for each benchmark")
var benchmarkMemory = flag.Bool("test.benchmem", false, "print memory allocations for benchmarks")
// Global lock to ensure only one benchmark runs at a time.
......@@ -178,7 +178,7 @@ func (b *B) launch() {
b.runN(n)
// Run the benchmark for at least the specified amount of time.
d := time.Duration(*benchTime * float64(time.Second))
d := *benchTime
for !b.failed && b.duration < d && n < 1e9 {
last := n
// Predict iterations/sec.
......
......@@ -38,9 +38,9 @@ func BenchmarkSlowNonASCII(b *testing.B) {
}
func main() {
os.Args = []string{os.Args[0], "-test.benchtime=0.1"}
os.Args = []string{os.Args[0], "-test.benchtime=100ms"}
flag.Parse()
rslow := testing.Benchmark(BenchmarkSlowNonASCII)
rfast := testing.Benchmark(BenchmarkFastNonASCII)
tslow := rslow.NsPerOp()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment