diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-01-14 00:05:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-01-14 00:05:42 +0000 |
commit | c2047754c300b68c05d65faa8dc2925fe67b71b4 (patch) | |
tree | e183ae81a1f48a02945cb6de463a70c5be1b06f6 /libgo/go/testing/benchmark.go | |
parent | 829afb8f05602bb31c9c597b24df7377fed4f059 (diff) | |
download | gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.zip gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.gz gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.bz2 |
libgo: update to Go 1.8 release candidate 1
Compiler changes:
* Change map assignment to use mapassign and assign value directly.
* Change string iteration to use decoderune, faster for ASCII strings.
* Change makeslice to take int, and use makeslice64 for larger values.
* Add new noverflow field to hmap struct used for maps.
Unresolved problems, to be fixed later:
* Commented out test in go/types/sizes_test.go that doesn't compile.
* Commented out reflect.TestStructOf test for padding after zero-sized field.
Reviewed-on: https://go-review.googlesource.com/35231
gotools/:
Updates for Go 1.8rc1.
* Makefile.am (go_cmd_go_files): Add bug.go.
(s-zdefaultcc): Write defaultPkgConfig.
* Makefile.in: Rebuild.
From-SVN: r244456
Diffstat (limited to 'libgo/go/testing/benchmark.go')
-rw-r--r-- | libgo/go/testing/benchmark.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libgo/go/testing/benchmark.go b/libgo/go/testing/benchmark.go index 5d58b85..c033ce5 100644 --- a/libgo/go/testing/benchmark.go +++ b/libgo/go/testing/benchmark.go @@ -7,6 +7,7 @@ package testing import ( "flag" "fmt" + "internal/race" "os" "runtime" "sync" @@ -14,8 +15,8 @@ import ( "time" ) -var matchBenchmarks = flag.String("test.bench", "", "regular expression per path component to select benchmarks to run") -var benchTime = flag.Duration("test.benchtime", 1*time.Second, "approximate run time for each benchmark") +var matchBenchmarks = flag.String("test.bench", "", "run only benchmarks matching `regexp`") +var benchTime = flag.Duration("test.benchtime", 1*time.Second, "run each benchmark for duration `d`") var benchmarkMemory = flag.Bool("test.benchmem", false, "print memory allocations for benchmarks") // Global lock to ensure only one benchmark runs at a time. @@ -56,7 +57,6 @@ type B struct { missingBytes bool // one of the subbenchmarks does not have bytes set. timerOn bool showAllocResult bool - hasSub bool result BenchmarkResult parallelism int // RunParallel creates parallelism*GOMAXPROCS goroutines // The initial states of memStats.Mallocs and memStats.TotalAlloc. @@ -132,6 +132,7 @@ func (b *B) runN(n int) { // Try to get a comparable environment for each run // by clearing garbage from previous runs. runtime.GC() + b.raceErrors = -race.Errors() b.N = n b.parallelism = 1 b.ResetTimer() @@ -140,6 +141,10 @@ func (b *B) runN(n int) { b.StopTimer() b.previousN = n b.previousDuration = b.duration + b.raceErrors += race.Errors() + if b.raceErrors > 0 { + b.Errorf("race detected during execution of benchmark") + } } func min(x, y int) int { @@ -263,10 +268,9 @@ func (b *B) launch() { for n := 1; !b.failed && b.duration < d && n < 1e9; { last := n // Predict required iterations. - if b.nsPerOp() == 0 { - n = 1e9 - } else { - n = int(d.Nanoseconds() / b.nsPerOp()) + n = int(d.Nanoseconds()) + if nsop := b.nsPerOp(); nsop != 0 { + n /= int(nsop) } // Run more iterations than we think we'll need (1.2x). // Don't grow too fast in case we had timing errors previously. @@ -359,10 +363,10 @@ type benchContext struct { // An internal function but exported because it is cross-package; part of the implementation // of the "go test" command. func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) { - runBenchmarksInternal(matchString, benchmarks) + runBenchmarks(matchString, benchmarks) } -func runBenchmarksInternal(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) bool { +func runBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) bool { // If no flag was specified, don't run benchmarks. if len(*matchBenchmarks) == 0 { return true |