cri-o/vendor/github.com/mailru/easyjson/benchmark/default_test.go
Jacek J. Łakis bf51655a7b vendor: Update vendoring for the exec client and server implementations
Signed-off-by: Jacek J. Łakis <jacek.lakis@intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2017-04-24 18:38:41 +02:00

118 lines
2.1 KiB
Go

// +build !use_easyjson,!use_ffjson,!use_codec
package benchmark
import (
"encoding/json"
"testing"
)
func BenchmarkStd_Unmarshal_M(b *testing.B) {
b.SetBytes(int64(len(largeStructText)))
for i := 0; i < b.N; i++ {
var s LargeStruct
err := json.Unmarshal(largeStructText, &s)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkStd_Unmarshal_S(b *testing.B) {
for i := 0; i < b.N; i++ {
var s Entities
err := json.Unmarshal(smallStructText, &s)
if err != nil {
b.Error(err)
}
}
b.SetBytes(int64(len(smallStructText)))
}
func BenchmarkStd_Marshal_M(b *testing.B) {
var l int64
for i := 0; i < b.N; i++ {
data, err := json.Marshal(&largeStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
b.SetBytes(l)
}
func BenchmarkStd_Marshal_L(b *testing.B) {
var l int64
for i := 0; i < b.N; i++ {
data, err := json.Marshal(&xlStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
b.SetBytes(l)
}
func BenchmarkStd_Marshal_M_Parallel(b *testing.B) {
var l int64
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
data, err := json.Marshal(&largeStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
})
b.SetBytes(l)
}
func BenchmarkStd_Marshal_L_Parallel(b *testing.B) {
var l int64
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
data, err := json.Marshal(&xlStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
})
b.SetBytes(l)
}
func BenchmarkStd_Marshal_S(b *testing.B) {
var l int64
for i := 0; i < b.N; i++ {
data, err := json.Marshal(&smallStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
b.SetBytes(l)
}
func BenchmarkStd_Marshal_S_Parallel(b *testing.B) {
var l int64
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
data, err := json.Marshal(&smallStructData)
if err != nil {
b.Error(err)
}
l = int64(len(data))
}
})
b.SetBytes(l)
}
func BenchmarkStd_Marshal_M_ToWriter(b *testing.B) {
enc := json.NewEncoder(&DummyWriter{})
for i := 0; i < b.N; i++ {
err := enc.Encode(&largeStructData)
if err != nil {
b.Error(err)
}
}
}