From 6cd0ab4ca917112cc94c496a08d1b0e7357e2c37 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 28 Apr 2021 16:59:01 +0900 Subject: [PATCH] Add valyala/fastjson to benchmark --- benchmarks/decode_test.go | 34 ++++++++++++++++++++++++++++++++++ benchmarks/go.mod | 1 + benchmarks/go.sum | 2 ++ 3 files changed, 37 insertions(+) diff --git a/benchmarks/decode_test.go b/benchmarks/decode_test.go index aeb33db..805645c 100644 --- a/benchmarks/decode_test.go +++ b/benchmarks/decode_test.go @@ -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) { @@ -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++ { @@ -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++ { @@ -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++ { diff --git a/benchmarks/go.mod b/benchmarks/go.mod index 5872cac..54482e7 100644 --- a/benchmarks/go.mod +++ b/benchmarks/go.mod @@ -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 ) diff --git a/benchmarks/go.sum b/benchmarks/go.sum index e2454fa..8dc49da 100644 --- a/benchmarks/go.sum +++ b/benchmarks/go.sum @@ -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=