Skip to content

Commit

Permalink
Merge pull request goccy#193 from goccy/feature/add-fastjson-to-bench…
Browse files Browse the repository at this point in the history
…mark

Add valyala/fastjson to benchmark
  • Loading branch information
goccy committed Apr 28, 2021
2 parents df4c91a + 6cd0ab4 commit 4d51b8b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions benchmarks/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
gojson "github.com/goccy/go-json"
jsoniter "github.com/json-iterator/go"
segmentiojson "github.com/segmentio/encoding/json"
fastjson "github.com/valyala/fastjson"
)

func Benchmark_Decode_SmallStruct_Unmarshal_EncodingJson(b *testing.B) {
Expand All @@ -21,6 +22,17 @@ func Benchmark_Decode_SmallStruct_Unmarshal_EncodingJson(b *testing.B) {
}
}

func Benchmark_Decode_SmallStruct_Unmarshal_FastJson(b *testing.B) {
smallFixture := string(SmallFixture)
b.ReportAllocs()
for n := 0; n < b.N; n++ {
var p fastjson.Parser
if _, err := p.Parse(smallFixture); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
Expand Down Expand Up @@ -151,6 +163,17 @@ func Benchmark_Decode_MediumStruct_Unmarshal_EncodingJson(b *testing.B) {
}
}

func Benchmark_Decode_MediumStruct_Unmarshal_FastJson(b *testing.B) {
mediumFixture := string(MediumFixture)
b.ReportAllocs()
for n := 0; n < b.N; n++ {
var p fastjson.Parser
if _, err := p.Parse(mediumFixture); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_MediumStruct_Unmarshal_JsonIter(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
Expand Down Expand Up @@ -281,6 +304,17 @@ func Benchmark_Decode_LargeStruct_Unmarshal_EncodingJson(b *testing.B) {
}
}

func Benchmark_Decode_LargeStruct_Unmarshal_FastJson(b *testing.B) {
largeFixture := string(LargeFixture)
b.ReportAllocs()
for n := 0; n < b.N; n++ {
var p fastjson.Parser
if _, err := p.Parse(largeFixture); err != nil {
b.Fatal(err)
}
}
}

func Benchmark_Decode_LargeStruct_Unmarshal_JsonIter(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
Expand Down
1 change: 1 addition & 0 deletions benchmarks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/json-iterator/go v1.1.9
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe
github.com/segmentio/encoding v0.2.4
github.com/valyala/fastjson v1.6.3
github.com/wI2L/jettison v0.7.1
)

Expand Down
2 changes: 2 additions & 0 deletions benchmarks/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/wI2L/jettison v0.7.1 h1:XNq/WvSOAiJhFww9F5JZZcBZtKFL2Y/9WHHEHLDq9TE=
Expand Down

0 comments on commit 4d51b8b

Please sign in to comment.