aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2019-03-03 18:31:33 +0000
committerDaniel Martí <mvdan@mvdan.cc>2019-03-03 18:43:53 +0000
commit83610c90bbe4f5f0b18ac01da3f3921c2f7090e4 (patch)
tree12651c2acd79c760ef93c2d881ac82c5a5e1f46a /src/os/exec
parent42b79f08239216eeea3cc1b0febc992f91bd88de (diff)
downloadgo-83610c90bbe4f5f0b18ac01da3f3921c2f7090e4.tar.xz
os/exec: don't use the echo binary for a benchmark
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í <mvdan@mvdan.cc> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/os/exec')
-rw-r--r--src/os/exec/bench_test.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/os/exec/bench_test.go b/src/os/exec/bench_test.go
index e8cf73bef7..9a94001e84 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)
}
}
}