From: Russ Cox Date: Thu, 14 Apr 2011 14:59:33 +0000 (-0400) Subject: gotest: add timing, respect $GOARCH X-Git-Tag: weekly.2011-04-27~164 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3441bda959fe6b5ff4f0f14362451d99f6a56ccd;p=gostls13.git gotest: add timing, respect $GOARCH R=r, r2 CC=golang-dev https://golang.org/cl/4370049 --- diff --git a/src/cmd/gotest/gotest.go b/src/cmd/gotest/gotest.go index 138216e681..a72f8d41e8 100644 --- a/src/cmd/gotest/gotest.go +++ b/src/cmd/gotest/gotest.go @@ -16,6 +16,7 @@ import ( "path/filepath" "runtime" "strings" + "time" "unicode" "utf8" ) @@ -51,6 +52,13 @@ var ( xFlag bool ) +// elapsed returns time elapsed since gotest started. +func elapsed() float64 { + return float64(time.Nanoseconds()-start) / 1e9 +} + +var start = time.Nanoseconds() + // File represents a file that contains tests. type File struct { name string @@ -80,6 +88,9 @@ func main() { if !cFlag { runTestWithArgs("./" + O + ".out") } + if xFlag { + fmt.Printf("gotest %.2fs: done\n", elapsed()) + } } // needMakefile tests that we have a Makefile in this directory. @@ -119,7 +130,10 @@ func setEnvironment() { // Basic environment. GOROOT = runtime.GOROOT() addEnv("GOROOT", GOROOT) - GOARCH = runtime.GOARCH + GOARCH = os.Getenv("GOARCH") + if GOARCH == "" { + GOARCH = runtime.GOARCH + } addEnv("GOARCH", GOARCH) O = theChar[GOARCH] if O == "" { @@ -254,7 +268,12 @@ func runTestWithArgs(binary string) { // retrieve standard output. func doRun(argv []string, returnStdout bool) string { if xFlag { - fmt.Printf("gotest: %s\n", strings.Join(argv, " ")) + fmt.Printf("gotest %.2fs: %s\n", elapsed(), strings.Join(argv, " ")) + t := -time.Nanoseconds() + defer func() { + t += time.Nanoseconds() + fmt.Printf(" [+%.2fs]\n", float64(t)/1e9) + }() } command := argv[0] if runtime.GOOS == "windows" && command == "gomake" {