mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Make BenchmarkBashCompletion more honest
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)
This commit is contained in:
parent
66da711334
commit
84f471618b
1 changed files with 3 additions and 7 deletions
|
@ -2,7 +2,6 @@ package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -181,15 +180,12 @@ func BenchmarkBashCompletion(b *testing.B) {
|
||||||
cmdEcho.AddCommand(cmdTimes)
|
cmdEcho.AddCommand(cmdTimes)
|
||||||
c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon)
|
c.AddCommand(cmdEcho, cmdPrint, cmdDeprecated, cmdColon)
|
||||||
|
|
||||||
file, err := ioutil.TempFile("", "")
|
buf := new(bytes.Buffer)
|
||||||
if err != nil {
|
|
||||||
b.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.Remove(file.Name())
|
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
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)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue