From 4b052e7192dec9a7eebd6f9c8391df0aa0150b76 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Tue, 23 Sep 2014 17:55:14 +0400 Subject: [PATCH] Benchmark for jsonlog.WriteLog Signed-off-by: Alexandr Morozov --- jsonlog/jsonlog_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 jsonlog/jsonlog_test.go diff --git a/jsonlog/jsonlog_test.go b/jsonlog/jsonlog_test.go new file mode 100644 index 0000000..13b8dbe --- /dev/null +++ b/jsonlog/jsonlog_test.go @@ -0,0 +1,33 @@ +package jsonlog + +import ( + "bytes" + "encoding/json" + "io/ioutil" + "testing" + "time" + + "github.com/docker/docker/pkg/timeutils" +) + +func BenchmarkWriteLog(b *testing.B) { + var buf bytes.Buffer + e := json.NewEncoder(&buf) + testLine := "Line that thinks that it is log line from docker\n" + for i := 0; i < 30; i++ { + e.Encode(JSONLog{Log: testLine, Stream: "stdout", Created: time.Now()}) + } + r := bytes.NewReader(buf.Bytes()) + w := ioutil.Discard + format := timeutils.RFC3339NanoFixed + b.SetBytes(int64(r.Len())) + b.ResetTimer() + for i := 0; i < b.N; i++ { + if err := WriteLog(r, w, format); err != nil { + b.Fatal(err) + } + b.StopTimer() + r.Seek(0, 0) + b.StartTimer() + } +}