From 55cac6c9421702ca1e42b3e3f92266e865a5c769 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Wed, 17 Sep 2014 19:24:07 +0400 Subject: [PATCH] Benchmark for StdWriter.Write Signed-off-by: Alexandr Morozov --- pkg/stdcopy/stdcopy_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pkg/stdcopy/stdcopy_test.go diff --git a/pkg/stdcopy/stdcopy_test.go b/pkg/stdcopy/stdcopy_test.go new file mode 100644 index 0000000000000..14e6ed3115ce7 --- /dev/null +++ b/pkg/stdcopy/stdcopy_test.go @@ -0,0 +1,20 @@ +package stdcopy + +import ( + "bytes" + "io/ioutil" + "testing" +) + +func BenchmarkWrite(b *testing.B) { + w := NewStdWriter(ioutil.Discard, Stdout) + data := []byte("Test line for testing stdwriter performance\n") + data = bytes.Repeat(data, 100) + b.SetBytes(int64(len(data))) + b.ResetTimer() + for i := 0; i < b.N; i++ { + if _, err := w.Write(data); err != nil { + b.Fatal(err) + } + } +}