Benchmark for jsonlog.WriteLog
Signed-off-by: Alexandr Morozov <lk4d4@docker.com>
This commit is contained in:
parent
c8ef31d338
commit
4b052e7192
1 changed files with 33 additions and 0 deletions
33
jsonlog/jsonlog_test.go
Normal file
33
jsonlog/jsonlog_test.go
Normal file
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue