forked from mirror/cobra
doc: Use w.Write instead of fmt in yaml_docs
benchmark old ns/op new ns/op delta BenchmarkGenYamlToFile-4 62488 61622 -1.39% benchmark old allocs new allocs delta BenchmarkGenYamlToFile-4 121 120 -0.83% benchmark old bytes new bytes delta BenchmarkGenYamlToFile-4 26706 26280 -1.60%
This commit is contained in:
parent
97af803f3b
commit
6dd90846ba
|
@ -130,7 +130,8 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) str
|
|||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if _, err := fmt.Fprintf(w, string(final)); err != nil {
|
||||
|
||||
if _, err := w.Write(final); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -106,3 +106,20 @@ func TestGenYamlTree(t *testing.T) {
|
|||
t.Fatalf("Expected file 'do.yaml' to exist")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGenYamlToFile(b *testing.B) {
|
||||
c := initializeWithRootCmd()
|
||||
file, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
defer file.Close()
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if err := GenYaml(c, file); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue