From 029bc76843328dac6db486f3f9d48523d5f13903 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Tue, 1 Jun 2021 15:50:26 +0900 Subject: [PATCH] Add benchmark for colorize option --- benchmarks/encode_test.go | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/benchmarks/encode_test.go b/benchmarks/encode_test.go index 619c496..b64f47a 100644 --- a/benchmarks/encode_test.go +++ b/benchmarks/encode_test.go @@ -67,6 +67,16 @@ func Benchmark_Encode_SmallStruct_SegmentioJson(b *testing.B) { } } +func Benchmark_Encode_SmallStruct_GoJsonColored(b *testing.B) { + colorOpt := gojson.Colorize(gojson.DefaultColorScheme) + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.MarshalWithOption(NewSmallPayload(), colorOpt); err != nil { + b.Fatal(err) + } + } +} + func Benchmark_Encode_SmallStruct_GoJson(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -146,6 +156,17 @@ func Benchmark_Encode_SmallStructCached_SegmentioJson(b *testing.B) { } } +func Benchmark_Encode_SmallStructCached_GoJsonColored(b *testing.B) { + cached := NewSmallPayload() + colorOpt := gojson.Colorize(gojson.DefaultColorScheme) + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.MarshalWithOption(cached, colorOpt); err != nil { + b.Fatal(err) + } + } +} + func Benchmark_Encode_SmallStructCached_GoJson(b *testing.B) { cached := NewSmallPayload() b.ReportAllocs() @@ -221,6 +242,16 @@ func Benchmark_Encode_MediumStruct_SegmentioJson(b *testing.B) { } } +func Benchmark_Encode_MediumStruct_GoJsonColored(b *testing.B) { + colorOpt := gojson.Colorize(gojson.DefaultColorScheme) + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.MarshalWithOption(NewMediumPayload(), colorOpt); err != nil { + b.Fatal(err) + } + } +} + func Benchmark_Encode_MediumStruct_GoJson(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -300,6 +331,17 @@ func Benchmark_Encode_MediumStructCached_SegmentioJson(b *testing.B) { } } +func Benchmark_Encode_MediumStructCached_GoJsonColored(b *testing.B) { + cached := NewMediumPayload() + colorOpt := gojson.Colorize(gojson.DefaultColorScheme) + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.MarshalWithOption(cached, colorOpt); err != nil { + b.Fatal(err) + } + } +} + func Benchmark_Encode_MediumStructCached_GoJson(b *testing.B) { cached := NewMediumPayload() b.ReportAllocs() @@ -375,6 +417,16 @@ func Benchmark_Encode_LargeStruct_SegmentioJson(b *testing.B) { } } +func Benchmark_Encode_LargeStruct_GoJsonColored(b *testing.B) { + colorOpt := gojson.Colorize(gojson.DefaultColorScheme) + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.MarshalWithOption(NewLargePayload(), colorOpt); err != nil { + b.Fatal(err) + } + } +} + func Benchmark_Encode_LargeStruct_GoJson(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -454,6 +506,17 @@ func Benchmark_Encode_LargeStructCached_SegmentioJson(b *testing.B) { } } +func Benchmark_Encode_LargeStructCached_GoJsonColored(b *testing.B) { + cached := NewLargePayload() + colorOpt := gojson.Colorize(gojson.DefaultColorScheme) + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := gojson.MarshalWithOption(cached, colorOpt); err != nil { + b.Fatal(err) + } + } +} + func Benchmark_Encode_LargeStructCached_GoJson(b *testing.B) { cached := NewLargePayload() b.ReportAllocs()