From 84f471618b363c4e298af84c2b53aa4f687c5f70 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Mon, 5 Jun 2017 19:32:33 +0200 Subject: [PATCH] Make BenchmarkBashCompletion more honest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta BashCompletion-4 67.4µs ± 1% 50.8µs ± 3% -24.63% (p=0.000 n=17+19) name old alloc/op new alloc/op delta BashCompletion-4 29.5kB ± 0% 29.5kB ± 0% +0.00% (p=0.020 n=20+20) name old allocs/op new allocs/op delta BashCompletion-4 253 ± 0% 253 ± 0% ~ (all equal) --- bash_completions_test.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bash_completions_test.go b/bash_completions_test.go index a626360b..7511376a 100644 --- a/bash_completions_test.go +++ b/bash_completions_test.go @@ -2,7 +2,6 @@ package cobra import ( "bytes" - "io/ioutil" "os" "os/exec" "strings" @@ -181,15 +180,12 @@ func BenchmarkBashCompletion(b *testing.B) { cmdEcho.AddCommand(cmdTimes) c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon) - file, err := ioutil.TempFile("", "") - if err != nil { - b.Fatal(err) - } - defer os.Remove(file.Name()) + buf := new(bytes.Buffer) b.ResetTimer() for i := 0; i < b.N; i++ { - if err := c.GenBashCompletion(file); err != nil { + buf.Reset() + if err := c.GenBashCompletion(buf); err != nil { b.Fatal(err) } }