Skip to content

Commit

Permalink
Merge pull request #254 from goccy/feature/add-sonic-to-benchmark
Browse files Browse the repository at this point in the history
Add bytedance/sonic to benchmark target
  • Loading branch information
goccy committed Jun 23, 2021
2 parents 4f9edb7 + 291234a commit f7eceb1
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 59 deletions.
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

0 comments on commit f7eceb1

Please sign in to comment.