mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: parallelize tests over count
Currently all package tests are executed once with Parallel tests executed in parallel. Then this process is repeated count*cpu times. Tests are not parallelized over count*cpu. Parallelizing over cpu is not possible as GOMAXPROCS is a global setting. But it is possible for count. Parallelize over count. Brings down testing of my package with -count=100 form 10s to 0.3s. Change-Id: I76d8322adeb8c5c6e70b99af690291fd69d6402a Reviewed-on: https://go-review.googlesource.com/44830 Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
f7aa454c58
commit
f04d583618
2 changed files with 63 additions and 63 deletions
|
|
@ -427,11 +427,12 @@ func runBenchmarks(importPath string, matchString func(pat, str string) (bool, e
|
|||
// processBench runs bench b for the configured CPU counts and prints the results.
|
||||
func (ctx *benchContext) processBench(b *B) {
|
||||
for i, procs := range cpuList {
|
||||
for j := uint(0); j < *count; j++ {
|
||||
runtime.GOMAXPROCS(procs)
|
||||
benchName := benchmarkName(b.name, procs)
|
||||
fmt.Fprintf(b.w, "%-*s\t", ctx.maxLen, benchName)
|
||||
// Recompute the running time for all but the first iteration.
|
||||
if i > 0 {
|
||||
if i > 0 || j > 0 {
|
||||
b = &B{
|
||||
common: common{
|
||||
signal: make(chan bool),
|
||||
|
|
@ -467,6 +468,7 @@ func (ctx *benchContext) processBench(b *B) {
|
|||
fmt.Fprintf(os.Stderr, "testing: %s left GOMAXPROCS set to %d\n", benchName, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run benchmarks f as a subbenchmark with the given name. It reports
|
||||
|
|
|
|||
|
|
@ -991,6 +991,7 @@ func runTests(matchString func(pat, str string) (bool, error), tests []InternalT
|
|||
ok = true
|
||||
for _, procs := range cpuList {
|
||||
runtime.GOMAXPROCS(procs)
|
||||
for i := uint(0); i < *count; i++ {
|
||||
ctx := newTestContext(*parallel, newMatcher(matchString, *match, "-test.run"))
|
||||
t := &T{
|
||||
common: common{
|
||||
|
|
@ -1013,6 +1014,7 @@ func runTests(matchString func(pat, str string) (bool, error), tests []InternalT
|
|||
ok = ok && !t.Failed()
|
||||
ran = ran || t.ran
|
||||
}
|
||||
}
|
||||
return ran, ok
|
||||
}
|
||||
|
||||
|
|
@ -1167,13 +1169,9 @@ func parseCpuList() {
|
|||
fmt.Fprintf(os.Stderr, "testing: invalid value %q for -test.cpu\n", val)
|
||||
os.Exit(1)
|
||||
}
|
||||
for i := uint(0); i < *count; i++ {
|
||||
cpuList = append(cpuList, cpu)
|
||||
}
|
||||
}
|
||||
if cpuList == nil {
|
||||
for i := uint(0); i < *count; i++ {
|
||||
cpuList = append(cpuList, runtime.GOMAXPROCS(-1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue