diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-01-29 14:17:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 14:17:40 -0800 |
commit | 961c04cae992eadb42d286d2f85f8a675bdc68c8 (patch) | |
tree | 3408f2d06f847e966c53485e2d54c692cdd037c1 /vendor/github.com/mailru/easyjson/benchmark/easyjson_test.go | |
parent | 8d66523ba7d9a77129844be476732ebfd5272d64 (diff) | |
download | chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.gz chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.bz2 chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.zip |
Upgrading server dependancies (#8154)
Diffstat (limited to 'vendor/github.com/mailru/easyjson/benchmark/easyjson_test.go')
-rw-r--r-- | vendor/github.com/mailru/easyjson/benchmark/easyjson_test.go | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/vendor/github.com/mailru/easyjson/benchmark/easyjson_test.go b/vendor/github.com/mailru/easyjson/benchmark/easyjson_test.go new file mode 100644 index 000000000..16b670b27 --- /dev/null +++ b/vendor/github.com/mailru/easyjson/benchmark/easyjson_test.go @@ -0,0 +1,184 @@ +// +build use_easyjson + +package benchmark + +import ( + "testing" + + "github.com/mailru/easyjson" + "github.com/mailru/easyjson/jwriter" +) + +func BenchmarkEJ_Unmarshal_M(b *testing.B) { + b.SetBytes(int64(len(largeStructText))) + for i := 0; i < b.N; i++ { + var s LargeStruct + err := s.UnmarshalJSON(largeStructText) + if err != nil { + b.Error(err) + } + } +} + +func BenchmarkEJ_Unmarshal_S(b *testing.B) { + b.SetBytes(int64(len(smallStructText))) + + for i := 0; i < b.N; i++ { + var s Entities + err := s.UnmarshalJSON(smallStructText) + if err != nil { + b.Error(err) + } + } +} + +func BenchmarkEJ_Marshal_M(b *testing.B) { + var l int64 + for i := 0; i < b.N; i++ { + data, err := easyjson.Marshal(&largeStructData) + if err != nil { + b.Error(err) + } + l = int64(len(data)) + } + b.SetBytes(l) +} + +func BenchmarkEJ_Marshal_L(b *testing.B) { + var l int64 + for i := 0; i < b.N; i++ { + data, err := easyjson.Marshal(&xlStructData) + if err != nil { + b.Error(err) + } + l = int64(len(data)) + } + b.SetBytes(l) +} + +func BenchmarkEJ_Marshal_L_ToWriter(b *testing.B) { + var l int64 + out := &DummyWriter{} + for i := 0; i < b.N; i++ { + w := jwriter.Writer{} + xlStructData.MarshalEasyJSON(&w) + if w.Error != nil { + b.Error(w.Error) + } + + l = int64(w.Size()) + w.DumpTo(out) + } + b.SetBytes(l) + +} +func BenchmarkEJ_Marshal_M_Parallel(b *testing.B) { + b.SetBytes(int64(len(largeStructText))) + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + _, err := largeStructData.MarshalJSON() + if err != nil { + b.Error(err) + } + } + }) +} + +func BenchmarkEJ_Marshal_M_ToWriter(b *testing.B) { + var l int64 + out := &DummyWriter{} + for i := 0; i < b.N; i++ { + w := jwriter.Writer{} + largeStructData.MarshalEasyJSON(&w) + if w.Error != nil { + b.Error(w.Error) + } + + l = int64(w.Size()) + w.DumpTo(out) + } + b.SetBytes(l) + +} +func BenchmarkEJ_Marshal_M_ToWriter_Parallel(b *testing.B) { + out := &DummyWriter{} + + b.RunParallel(func(pb *testing.PB) { + var l int64 + for pb.Next() { + w := jwriter.Writer{} + largeStructData.MarshalEasyJSON(&w) + if w.Error != nil { + b.Error(w.Error) + } + + l = int64(w.Size()) + w.DumpTo(out) + } + if l > 0 { + b.SetBytes(l) + } + }) + +} + +func BenchmarkEJ_Marshal_L_Parallel(b *testing.B) { + var l int64 + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + data, err := xlStructData.MarshalJSON() + if err != nil { + b.Error(err) + } + l = int64(len(data)) + } + }) + b.SetBytes(l) +} + +func BenchmarkEJ_Marshal_L_ToWriter_Parallel(b *testing.B) { + out := &DummyWriter{} + b.RunParallel(func(pb *testing.PB) { + var l int64 + for pb.Next() { + w := jwriter.Writer{} + + xlStructData.MarshalEasyJSON(&w) + if w.Error != nil { + b.Error(w.Error) + } + l = int64(w.Size()) + w.DumpTo(out) + } + if l > 0 { + b.SetBytes(l) + } + }) +} + +func BenchmarkEJ_Marshal_S(b *testing.B) { + var l int64 + for i := 0; i < b.N; i++ { + data, err := smallStructData.MarshalJSON() + if err != nil { + b.Error(err) + } + l = int64(len(data)) + } + b.SetBytes(l) +} + +func BenchmarkEJ_Marshal_S_Parallel(b *testing.B) { + var l int64 + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + data, err := smallStructData.MarshalJSON() + if err != nil { + b.Error(err) + } + l = int64(len(data)) + } + }) + b.SetBytes(l) +} |