From 1c0b7e7c7df69bb71c51c935fd0f6f8374b8fdbb Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sun, 31 Jan 2021 01:49:35 +0900 Subject: [PATCH] Add benchmark for encoding of bool type --- benchmarks/encode_test.go | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/benchmarks/encode_test.go b/benchmarks/encode_test.go index 7031b58..47c76db 100644 --- a/benchmarks/encode_test.go +++ b/benchmarks/encode_test.go @@ -558,6 +558,52 @@ func Benchmark_Encode_Interface_GoJson(b *testing.B) { } } +func Benchmark_Encode_Bool_EncodingJson(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := json.Marshal(true); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Bool_JsonIter(b *testing.B) { + var json = jsoniter.ConfigCompatibleWithStandardLibrary + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := json.Marshal(true); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Bool_Jettison(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := jettison.Marshal(true); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Bool_SegmentioJson(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := segmentiojson.Marshal(true); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Encode_Bool_GoJson(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.Marshal(true); err != nil { + b.Fatal(err) + } + } +} + func Benchmark_Encode_Int_EncodingJson(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ {