1// Copyright 2018 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package main_test 6 7import ( 8 "internal/testenv" 9 "os/exec" 10 "testing" 11) 12 13// BenchmarkExecGoEnv measures how long it takes for 'go env GOARCH' to run. 14// Since 'go' is executed, remember to run 'go install cmd/go' before running 15// the benchmark if any changes were done. 16func BenchmarkExecGoEnv(b *testing.B) { 17 testenv.MustHaveExec(b) 18 b.StopTimer() 19 gotool, err := testenv.GoTool() 20 if err != nil { 21 b.Fatal(err) 22 } 23 for i := 0; i < b.N; i++ { 24 cmd := exec.Command(gotool, "env", "GOARCH") 25 26 b.StartTimer() 27 err := cmd.Run() 28 b.StopTimer() 29 30 if err != nil { 31 b.Fatal(err) 32 } 33 } 34} 35