Source file
src/cmd/go/init_test.go
1
2
3
4
5 package main_test
6
7 import (
8 "internal/testenv"
9 "os/exec"
10 "sync/atomic"
11 "testing"
12 )
13
14
15
16
17 func BenchmarkExecGoEnv(b *testing.B) {
18 testenv.MustHaveExec(b)
19 gotool, err := testenv.GoTool()
20 if err != nil {
21 b.Fatal(err)
22 }
23
24
25 var n, userTime, systemTime int64
26
27 b.ResetTimer()
28 b.RunParallel(func(pb *testing.PB) {
29 for pb.Next() {
30 cmd := exec.Command(gotool, "env", "GOARCH")
31
32 if err := cmd.Run(); err != nil {
33 b.Fatal(err)
34 }
35 atomic.AddInt64(&n, 1)
36 atomic.AddInt64(&userTime, int64(cmd.ProcessState.UserTime()))
37 atomic.AddInt64(&systemTime, int64(cmd.ProcessState.SystemTime()))
38 }
39 })
40 b.ReportMetric(float64(userTime)/float64(n), "user-ns/op")
41 b.ReportMetric(float64(systemTime)/float64(n), "sys-ns/op")
42 }
43
View as plain text