Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bytedance/sonic to benchmark target #254

Merged
merged 2 commits into from Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
147 changes: 89 additions & 58 deletions benchmarks/decode_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"testing"

"github.com/bytedance/sonic"
gojay "github.com/francoispqt/gojay"
gojson "github.com/goccy/go-json"
jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -33,41 +34,51 @@ func Benchmark_Decode_SmallStruct_Unmarshal_FastJson(b *testing.B) {
}
}

func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) {
func Benchmark_Decode_SmallStruct_Unmarshal_SegmentioJson(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
result := SmallPayload{}
if err := jsoniter.Unmarshal(SmallFixture, &result); err != nil {
if err := segmentiojson.Unmarshal(SmallFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_SmallStruct_Unmarshal_GoJay(b *testing.B) {
func Benchmark_Decode_SmallStruct_Unmarshal_Sonic(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
result := SmallPayload{}
if err := gojay.UnmarshalJSONObject(SmallFixture, &result); err != nil {
if err := sonic.Unmarshal(SmallFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_SmallStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for n := 0; n < b.N; n++ {
result := SmallPayload{}
if err := gojay.Unsafe.UnmarshalJSONObject(SmallFixture, &result); err != nil {
if err := jsoniter.Unmarshal(SmallFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_SmallStruct_Unmarshal_SegmentioJson(b *testing.B) {
func Benchmark_Decode_SmallStruct_Unmarshal_GoJay(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
result := SmallPayload{}
if err := segmentiojson.Unmarshal(SmallFixture, &result); err != nil {
if err := gojay.UnmarshalJSONObject(SmallFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_SmallStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := SmallPayload{}
if err := gojay.Unsafe.UnmarshalJSONObject(SmallFixture, &result); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -105,37 +116,37 @@ func Benchmark_Decode_SmallStruct_Stream_EncodingJson(b *testing.B) {
}
}

func Benchmark_Decode_SmallStruct_Stream_JsonIter(b *testing.B) {
func Benchmark_Decode_SmallStruct_Stream_SegmentioJson(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(SmallFixture)
for i := 0; i < b.N; i++ {
result := SmallPayload{}
reader.Reset(SmallFixture)
if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil {
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_SmallStruct_Stream_GoJay(b *testing.B) {
func Benchmark_Decode_SmallStruct_Stream_JsonIter(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(SmallFixture)
for n := 0; n < b.N; n++ {
reader.Reset(SmallFixture)
for i := 0; i < b.N; i++ {
result := SmallPayload{}
if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil {
reader.Reset(SmallFixture)
if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_SmallStruct_Stream_SegmentioJson(b *testing.B) {
func Benchmark_Decode_SmallStruct_Stream_GoJay(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(SmallFixture)
for i := 0; i < b.N; i++ {
result := SmallPayload{}
for n := 0; n < b.N; n++ {
reader.Reset(SmallFixture)
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
result := SmallPayload{}
if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -174,41 +185,51 @@ func Benchmark_Decode_MediumStruct_Unmarshal_FastJson(b *testing.B) {
}
}

func Benchmark_Decode_MediumStruct_Unmarshal_JsonIter(b *testing.B) {
func Benchmark_Decode_MediumStruct_Unmarshal_Sonic(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
for i := 0; i < b.N; i++ {
result := MediumPayload{}
if err := jsoniter.Unmarshal(MediumFixture, &result); err != nil {
if err := sonic.Unmarshal(MediumFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_MediumStruct_Unmarshal_GoJay(b *testing.B) {
func Benchmark_Decode_MediumStruct_Unmarshal_SegmentioJson(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := MediumPayload{}
if err := segmentiojson.Unmarshal(MediumFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_MediumStruct_Unmarshal_JsonIter(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
result := MediumPayload{}
if err := gojay.UnmarshalJSONObject(MediumFixture, &result); err != nil {
if err := jsoniter.Unmarshal(MediumFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_MediumStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
func Benchmark_Decode_MediumStruct_Unmarshal_GoJay(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for n := 0; n < b.N; n++ {
result := MediumPayload{}
if err := gojay.Unsafe.UnmarshalJSONObject(MediumFixture, &result); err != nil {
if err := gojay.UnmarshalJSONObject(MediumFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_MediumStruct_Unmarshal_SegmentioJson(b *testing.B) {
func Benchmark_Decode_MediumStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := MediumPayload{}
if err := segmentiojson.Unmarshal(MediumFixture, &result); err != nil {
if err := gojay.Unsafe.UnmarshalJSONObject(MediumFixture, &result); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -246,37 +267,37 @@ func Benchmark_Decode_MediumStruct_Stream_EncodingJson(b *testing.B) {
}
}

func Benchmark_Decode_MediumStruct_Stream_JsonIter(b *testing.B) {
func Benchmark_Decode_MediumStruct_Stream_SegmentioJson(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(MediumFixture)
for i := 0; i < b.N; i++ {
result := MediumPayload{}
for n := 0; n < b.N; n++ {
reader.Reset(MediumFixture)
if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil {
result := MediumPayload{}
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_MediumStruct_Stream_GoJay(b *testing.B) {
func Benchmark_Decode_MediumStruct_Stream_JsonIter(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(MediumFixture)
for n := 0; n < b.N; n++ {
reader.Reset(MediumFixture)
for i := 0; i < b.N; i++ {
result := MediumPayload{}
if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil {
reader.Reset(MediumFixture)
if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_MediumStruct_Stream_SegmentioJson(b *testing.B) {
func Benchmark_Decode_MediumStruct_Stream_GoJay(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(MediumFixture)
for n := 0; n < b.N; n++ {
reader.Reset(MediumFixture)
result := MediumPayload{}
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -315,41 +336,51 @@ func Benchmark_Decode_LargeStruct_Unmarshal_FastJson(b *testing.B) {
}
}

func Benchmark_Decode_LargeStruct_Unmarshal_JsonIter(b *testing.B) {
func Benchmark_Decode_LargeStruct_Unmarshal_Sonic(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
result := LargePayload{}
if err := jsoniter.Unmarshal(LargeFixture, &result); err != nil {
if err := sonic.Unmarshal(LargeFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_LargeStruct_Unmarshal_GoJay(b *testing.B) {
func Benchmark_Decode_LargeStruct_Unmarshal_SegmentioJson(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := LargePayload{}
if err := segmentiojson.Unmarshal(LargeFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_LargeStruct_Unmarshal_JsonIter(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
result := LargePayload{}
if err := gojay.UnmarshalJSONObject(LargeFixture, &result); err != nil {
if err := jsoniter.Unmarshal(LargeFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_LargeStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
func Benchmark_Decode_LargeStruct_Unmarshal_GoJay(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for n := 0; n < b.N; n++ {
result := LargePayload{}
if err := gojay.Unsafe.UnmarshalJSONObject(LargeFixture, &result); err != nil {
if err := gojay.UnmarshalJSONObject(LargeFixture, &result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_LargeStruct_Unmarshal_SegmentioJson(b *testing.B) {
func Benchmark_Decode_LargeStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
result := LargePayload{}
if err := segmentiojson.Unmarshal(LargeFixture, &result); err != nil {
if err := gojay.Unsafe.UnmarshalJSONObject(LargeFixture, &result); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -415,37 +446,37 @@ func Benchmark_Decode_LargeStruct_Stream_EncodingJson(b *testing.B) {
}
}

func Benchmark_Decode_LargeStruct_Stream_JsonIter(b *testing.B) {
func Benchmark_Decode_LargeStruct_Stream_SegmentioJson(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(LargeFixture)
for i := 0; i < b.N; i++ {
result := LargePayload{}
reader.Reset(LargeFixture)
if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil {
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_LargeStruct_Stream_GoJay(b *testing.B) {
func Benchmark_Decode_LargeStruct_Stream_JsonIter(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(LargeFixture)
for n := 0; n < b.N; n++ {
reader.Reset(LargeFixture)
for i := 0; i < b.N; i++ {
result := LargePayload{}
if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil {
reader.Reset(LargeFixture)
if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_LargeStruct_Stream_SegmentioJson(b *testing.B) {
func Benchmark_Decode_LargeStruct_Stream_GoJay(b *testing.B) {
b.ReportAllocs()
reader := bytes.NewReader(LargeFixture)
for i := 0; i < b.N; i++ {
result := LargePayload{}
for n := 0; n < b.N; n++ {
reader.Reset(LargeFixture)
if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil {
result := LargePayload{}
if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil {
b.Fatal(err)
}
}
Expand Down