mirror of
https://github.com/golang/go
synced 2024-09-29 05:14:29 -06:00
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>
This commit is contained in:
parent
42b79f0823
commit
83610c90bb
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user