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:
Albert Nigmatzianov 2017-04-24 20:44:32 +02:00
parent 97af803f3b
commit 6dd90846ba
2 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -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)
}
}
}