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