From 83610c90bbe4f5f0b18ac01da3f3921c2f7090e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 3 Mar 2019 18:31:33 +0000 Subject: [PATCH] os/exec: don't use the echo binary for a benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most notably, it's missing on Windows machines. For example, windows-amd64-race started failing consistently: --- FAIL: BenchmarkExecEcho bench_test.go:15: could not find echo: exec: "echo": executable file not found in %PATH% We can also reproduce this from Linux with Wine: $ GOOS=windows go test -bench=. -benchtime=1x -run=- -exec wine --- FAIL: BenchmarkExecEcho bench_test.go:15: could not find echo: exec: "echo": executable file not found in %PATH% Instead, use the "hostname" program, which is available on Windows too. Interestingly enough, it's also slightly faster than "echo". Any program is fine as long as it's close enough to a no-op, though. name old time/op new time/op delta ExecEcho-8 422µs ± 0% 395µs ± 0% -6.39% (p=0.004 n=6+5) name old alloc/op new alloc/op delta ExecEcho-8 6.39kB ± 0% 6.42kB ± 0% +0.53% (p=0.002 n=6+6) name old allocs/op new allocs/op delta ExecEcho-8 36.0 ± 0% 36.0 ± 0% ~ (all equal) Change-Id: I772864d69979172b5cf807552c84d0e165e73051 Reviewed-on: https://go-review.googlesource.com/c/164704 Run-TryBot: Daniel Martí Reviewed-by: Josh Bleecher Snyder TryBot-Result: Gobot Gobot --- src/os/exec/bench_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/os/exec/bench_test.go b/src/os/exec/bench_test.go index e8cf73bef7d..9a94001e844 100644 --- a/src/os/exec/bench_test.go +++ b/src/os/exec/bench_test.go @@ -8,16 +8,16 @@ import ( "testing" ) -func BenchmarkExecEcho(b *testing.B) { +func BenchmarkExecHostname(b *testing.B) { b.ReportAllocs() - path, err := LookPath("echo") + path, err := LookPath("hostname") if err != nil { - b.Fatalf("could not find echo: %v", err) + b.Fatalf("could not find hostname: %v", err) } b.ResetTimer() for i := 0; i < b.N; i++ { if err := Command(path).Run(); err != nil { - b.Fatalf("echo: %v", err) + b.Fatalf("hostname: %v", err) } } }