Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (63 sloc) 1.42 KB
package go_benchmark
import (
"testing"
"github.com/json-iterator/go"
"encoding/json"
"github.com/mailru/easyjson/jlexer"
"bytes"
"github.com/mailru/easyjson/jwriter"
)
/*
encoding/json
*/
func BenchmarkDecodeStdStructMedium(b *testing.B) {
b.ReportAllocs()
var data MediumPayload
for i := 0; i < b.N; i++ {
json.Unmarshal(mediumFixture, &data)
}
}
func BenchmarkEncodeStdStructMedium(b *testing.B) {
var data MediumPayload
json.Unmarshal(mediumFixture, &data)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
json.Marshal(data)
}
}
func BenchmarkDecodeJsoniterStructMedium(b *testing.B) {
b.ReportAllocs()
var data MediumPayload
for i := 0; i < b.N; i++ {
jsoniter.Unmarshal(mediumFixture, &data)
}
}
func BenchmarkEncodeJsoniterStructMedium(b *testing.B) {
var data MediumPayload
jsoniter.Unmarshal(mediumFixture, &data)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
jsoniter.Marshal(data)
}
}
func BenchmarkDecodeEasyJsonMedium(b *testing.B) {
b.ReportAllocs()
var data MediumPayload
for i := 0; i < b.N; i++ {
lexer := &jlexer.Lexer{Data: mediumFixture}
data.UnmarshalEasyJSON(lexer)
}
}
func BenchmarkEncodeEasyJsonMedium(b *testing.B) {
var data MediumPayload
lexer := &jlexer.Lexer{Data: mediumFixture}
data.UnmarshalEasyJSON(lexer)
b.ReportAllocs()
buf := &bytes.Buffer{}
for i := 0; i < b.N; i++ {
writer := &jwriter.Writer{}
data.MarshalEasyJSON(writer)
buf.Reset()
writer.DumpTo(buf)
}
}