]> Cypherpunks repositories - gostls13.git/commitdiff
testing: change -test.benchtime to a flag.Duration.
authorDavid Symonds <dsymonds@golang.org>
Mon, 8 Oct 2012 21:57:29 +0000 (08:57 +1100)
committerDavid Symonds <dsymonds@golang.org>
Mon, 8 Oct 2012 21:57:29 +0000 (08:57 +1100)
Fixes #3902.

R=golang-dev, minux.ma, rsc, r
CC=golang-dev
https://golang.org/cl/6611059

misc/zsh/go
src/cmd/go/doc.go
src/cmd/go/test.go
src/cmd/go/testflag.go
src/pkg/go/doc/testdata/benchmark.go
src/pkg/go/doc/testdata/testing.1.golden
src/pkg/net/http/serve_test.go
src/pkg/testing/benchmark.go
test/fixedbugs/bug369.go

index 23afa96569e18d426125cd48921786e59a1faa2c..dce25547d4b5aca45959c2b758b4c16a5478843a 100644 (file)
@@ -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" \
index 7201065a66754a2dd403567830bfaace1ee03064..9e728163f832bf0acabc28aac215b47cee0e2b62 100644 (file)
@@ -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
index 0051fe1b93d6c421f932babdbb0e85fe31e24fa1..a55ecb95d8f4b765fe6226478de41f9971188f69 100644 (file)
@@ -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
index 48840cee51f0adfa35c05651a906f2b078e1a586..d73bfde20dc840cfacb6a6dea4e3b00922f905f0 100644 (file)
@@ -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
index 0aded5bb4c74cf263b8b691e545675ba72df9806..905e49644ad14f1524f138ef21494f67ed353d21 100644 (file)
@@ -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.
index d26a4685ca03ea04f8e0d45f9c10de1c364eba52..ffdb5c3b5887fbaae7c61282eec328617c9b95c1 100644 (file)
@@ -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")
index c5cf6ae7115c3f52150435bc07b4d15df70011c8..71b7b3fb6b7309c55a0c1136b00ae662a00510ff 100644 (file)
@@ -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) {
index 7a8cc1c4edf61c41f85a12f6dfa34e72af883ab1..cb92fab50adbf1bf115b16109abcd72d324eb41f 100644 (file)
@@ -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.
index 2ee8568e0441d2b7800cb8de9017f07708ad0424..6d526228b8a62f7c6a130b2d10f3e2f07ba486da 100644 (file)
@@ -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()