mirror of
https://github.com/golang/go
synced 2024-11-18 19:54:44 -07:00
cmd/compilebench: unify Size benchmark implementations
Change-Id: I181d9f9ce8880af8fbcdd43073d62f492725c85b Reviewed-on: https://go-review.googlesource.com/39717 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
89b6e5ee0d
commit
1cab72a478
@ -180,29 +180,22 @@ func runStdCmd() {
|
||||
runCmd("BenchmarkStdCmd", cmd)
|
||||
}
|
||||
|
||||
func runCmdGoSize() {
|
||||
runSize("BenchmarkCmdGoSize", filepath.Join(runtime.GOROOT(), "bin/go"))
|
||||
}
|
||||
|
||||
func runHelloSize() {
|
||||
cmd := exec.Command("go", "build", "-o", "_hello_", filepath.Join(runtime.GOROOT(), "test/helloworld.go"))
|
||||
// path is either a path to a file ("$GOROOT/test/helloworld.go") or a package path ("cmd/go").
|
||||
func runSize(name, path string) {
|
||||
cmd := exec.Command("go", "build", "-o", "_compilebenchout_", path)
|
||||
cmd.Stdout = os.Stderr
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
defer os.Remove("_hello_")
|
||||
runSize("BenchmarkHelloSize", "_hello_")
|
||||
}
|
||||
|
||||
func runSize(name, file string) {
|
||||
info, err := os.Stat(file)
|
||||
defer os.Remove("_compilebenchout_")
|
||||
info, err := os.Stat("_compilebenchout_")
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
out, err := exec.Command("size", file).CombinedOutput()
|
||||
out, err := exec.Command("size", "_compilebenchout_").CombinedOutput()
|
||||
if err != nil {
|
||||
log.Printf("size: %v\n%s", err, out)
|
||||
return
|
||||
@ -226,10 +219,10 @@ func runBuild(name, dir string) {
|
||||
runStdCmd()
|
||||
return
|
||||
case "BenchmarkCmdGoSize":
|
||||
runCmdGoSize()
|
||||
runSize("BenchmarkCmdGoSize", "cmd/go")
|
||||
return
|
||||
case "BenchmarkHelloSize":
|
||||
runHelloSize()
|
||||
runSize("BenchmarkHelloSize", filepath.Join(runtime.GOROOT(), "test/helloworld.go"))
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user