mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
05e4e805e0
commit
f8b5838123
|
|
@ -88,7 +88,7 @@ __go_tool_complete() {
|
||||||
"-cpu[values of GOMAXPROCS to use]:number list" \
|
"-cpu[values of GOMAXPROCS to use]:number list" \
|
||||||
"-run[run tests and examples matching regexp]:regexp" \
|
"-run[run tests and examples matching regexp]:regexp" \
|
||||||
"-bench[run benchmarks 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" \
|
"-timeout[kill test after that duration]:duration" \
|
||||||
"-cpuprofile[write CPU profile to file]:file:_files" \
|
"-cpuprofile[write CPU profile to file]:file:_files" \
|
||||||
"-memprofile[write heap 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
|
-test.timeout t
|
||||||
If a test runs longer than t, panic.
|
If a test runs longer than t, panic.
|
||||||
|
|
||||||
-test.benchtime n
|
-test.benchtime t
|
||||||
Run enough iterations of each benchmark to take n seconds.
|
Run enough iterations of each benchmark to take t.
|
||||||
The default is 1 second.
|
The default is 1 second.
|
||||||
|
|
||||||
-test.cpu 1,2,4
|
-test.cpu 1,2,4
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,8 @@ directory containing the package sources, has its own flags:
|
||||||
-test.timeout t
|
-test.timeout t
|
||||||
If a test runs longer than t, panic.
|
If a test runs longer than t, panic.
|
||||||
|
|
||||||
-test.benchtime n
|
-test.benchtime t
|
||||||
Run enough iterations of each benchmark to take n seconds.
|
Run enough iterations of each benchmark to take t.
|
||||||
The default is 1 second.
|
The default is 1 second.
|
||||||
|
|
||||||
-test.cpu 1,2,4
|
-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.
|
// These flags can be passed with or without a "test." prefix: -v or -test.v.
|
||||||
-bench="": passes -test.bench to test
|
-bench="": passes -test.bench to test
|
||||||
-benchmem=false: print memory allocation statistics for benchmarks
|
-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
|
-cpu="": passes -test.cpu to test
|
||||||
-cpuprofile="": passes -test.cpuprofile to test
|
-cpuprofile="": passes -test.cpuprofile to test
|
||||||
-memprofile="": passes -test.memprofile 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 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
|
// An internal type but exported because it is cross-package; part of the implementation
|
||||||
// of go test.
|
// of go test.
|
||||||
|
|
@ -151,7 +151,7 @@ func (b *B) launch() {
|
||||||
|
|
||||||
b.runN(n)
|
b.runN(n)
|
||||||
// Run the benchmark for at least the specified amount of time.
|
// 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 {
|
for !b.failed && b.duration < d && n < 1e9 {
|
||||||
last := n
|
last := n
|
||||||
// Predict iterations/sec.
|
// 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")
|
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:
|
// For use like:
|
||||||
// $ go test -c
|
// $ 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
|
// $ go tool pprof http.test http.prof
|
||||||
// (pprof) web
|
// (pprof) web
|
||||||
func BenchmarkServer(b *testing.B) {
|
func BenchmarkServer(b *testing.B) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var matchBenchmarks = flag.String("test.bench", "", "regular expression to select benchmarks to run")
|
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")
|
var benchmarkMemory = flag.Bool("test.benchmem", false, "print memory allocations for benchmarks")
|
||||||
|
|
||||||
// Global lock to ensure only one benchmark runs at a time.
|
// Global lock to ensure only one benchmark runs at a time.
|
||||||
|
|
@ -178,7 +178,7 @@ func (b *B) launch() {
|
||||||
|
|
||||||
b.runN(n)
|
b.runN(n)
|
||||||
// Run the benchmark for at least the specified amount of time.
|
// 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 {
|
for !b.failed && b.duration < d && n < 1e9 {
|
||||||
last := n
|
last := n
|
||||||
// Predict iterations/sec.
|
// Predict iterations/sec.
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ func BenchmarkSlowNonASCII(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
os.Args = []string{os.Args[0], "-test.benchtime=0.1"}
|
os.Args = []string{os.Args[0], "-test.benchtime=100ms"}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
rslow := testing.Benchmark(BenchmarkSlowNonASCII)
|
rslow := testing.Benchmark(BenchmarkSlowNonASCII)
|
||||||
rfast := testing.Benchmark(BenchmarkFastNonASCII)
|
rfast := testing.Benchmark(BenchmarkFastNonASCII)
|
||||||
tslow := rslow.NsPerOp()
|
tslow := rslow.NsPerOp()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue