From 2c95711d4526a12cc25ef1288ab605863a0d23da Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Tue, 26 Jan 2021 23:56:10 +0900 Subject: [PATCH] Add benchmark --- benchmarks/encode_test.go | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/benchmarks/encode_test.go b/benchmarks/encode_test.go index 4307fb7..be2c92c 100644 --- a/benchmarks/encode_test.go +++ b/benchmarks/encode_test.go @@ -537,3 +537,69 @@ func Benchmark_Encode_MapInterface_GoJson(b *testing.B) { } } } + +func Benchmark_Encode_Interface_SegmentioJson(b *testing.B) { + v := []interface{}{1} + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := segmentiojson.Marshal(v); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Interface_GoJson(b *testing.B) { + v := []interface{}{1} + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.Marshal(v); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Int_EncodingJson(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := json.Marshal(1); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Int_JsonIter(b *testing.B) { + var json = jsoniter.ConfigCompatibleWithStandardLibrary + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := json.Marshal(1); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Int_Jettison(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := jettison.Marshal(1); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Int_SegmentioJson(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := segmentiojson.Marshal(1); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Int_GoJson(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.Marshal(1); err != nil { + b.Fatal(err) + } + } +}