示例#1
0
func benchmarkOnce() driver.Result {
	// run 'go build -a'
	res := driver.MakeResult()
	cmd := exec.Command("go", "build", "-o", "gobuild", "-a", "-p", os.Getenv("GOMAXPROCS"), "cmd/go")
	out, err := driver.RunAndCollectSysStats(cmd, &res, 1, "build-")
	if err != nil {
		log.Fatalf("Failed to run 'go build -a cmd/go': %v\n%v", err, out)
	}

	// go command binary size
	gof, err := os.Open("gobuild")
	if err != nil {
		log.Fatalf("Failed to open $GOROOT/bin/go: %v\n", err)
	}
	st, err := gof.Stat()
	if err != nil {
		log.Fatalf("Failed to stat $GOROOT/bin/go: %v\n", err)
	}
	res.Metrics["binary-size"] = uint64(st.Size())

	sizef := driver.Size("gobuild")
	if sizef != "" {
		res.Files["sections"] = sizef
	}

	return res
}
示例#2
0
func benchmark() driver.Result {
	if os.Getenv("GOMAXPROCS") == "" {
		os.Setenv("GOMAXPROCS", "1")
	}
	res := driver.MakeResult()
	for i := 0; i < driver.BenchNum; i++ {
		res1 := benchmarkOnce()
		if res.RunTime == 0 || res.RunTime > res1.RunTime {
			res = res1
		}
		log.Printf("Run %v: %+v\n", i, res)
	}
	perf1, perf2 := driver.RunUnderProfiler("go", "build", "-o", "goperf", "-a", "-p", os.Getenv("GOMAXPROCS"), "cmd/go")
	if perf1 != "" {
		res.Files["processes"] = perf1
	}
	if perf2 != "" {
		res.Files["cpuprof"] = perf2
	}
	return res
}