Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version go1.7.1 darwin/amd64
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/cyli/Go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.1/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/v9/wzpq8hm56b943960j1qrnblm0000gp/T/go-build685341822=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
What did you do?
time go test $(go list ./... | grep -v vendor)
time go test $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
What did you expect to see?
I expected they would take the same mostly the same amount of time
What did you see instead?
time go test $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
is reliably faster. I've also tried running time for i in {1..10}; do <command>; done
and on average it is faster than not first excluding the packages without tests.
This is the case even if -parallel #
is set, whether or not -race
or if coverage numbers are generated. For instance, when running the tests for https://github.com/docker/swarmkit:
$ time go test -parallel 8 -race $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
...
real 0m17.380s
user 0m51.668s
sys 0m7.717s
$ time go test -parallel 8 -race $(go list ./... | grep -v vendor)
...
real 0m27.161s
user 1m26.491s
sys 0m15.368s
$ time go test $(go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
...
real 0m15.005s
user 0m41.354s
sys 0m6.796s
$ time go test $(go list ./... | grep -v vendor)
...
real 0m26.743s
user 1m4.753s
sys 0m13.017s
In case time
is excluding how long go list
takes:
$ time (go list ./... | grep -v vendor)
...
real 0m0.308s
user 0m0.239s
sys 0m0.136s
$ time (go list -f '{{ if .TestGoFiles }}{{ .ImportPath }}{{ end }}' ./... | grep -v vendor)
...
real 0m0.318s
user 0m0.248s
sys 0m0.141s
I'm not sure if this is the issue, but maybe go test
can automatically exclude packages provided to it that don't have tests first, and not even start building the test binary for those?
Activity
minux commentedon Sep 27, 2016
[-]`go test` takes extra time to run even for packages that do not have any test files[/-][+]cmd/go: `go test` takes extra time to run even for packages that do not have any test files[/+]cyli commentedon Sep 27, 2016
Oh, that makes sense. Thanks for linking the other issue!