]> Cypherpunks repositories - gostls13.git/commitdiff
os/exec: don't use the echo binary for a benchmark
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 3 Mar 2019 18:31:33 +0000 (18:31 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Sun, 3 Mar 2019 18:43:53 +0000 (18:43 +0000)
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>

src/os/exec/bench_test.go

index e8cf73bef7dd794562d79efb11b7f166b5b47cf6..9a94001e84483918581cb4de7c5b3ef0de241388 100644 (file)
@@ -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)
                }
        }
 }