Add benchmark for colorize option

This commit is contained in:
Masaaki Goshima 2021-06-01 15:50:26 +09:00
parent 847573aaf6
commit 029bc76843
1 changed files with 63 additions and 0 deletions

View File

@ -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) { func Benchmark_Encode_SmallStruct_GoJson(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { 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) { func Benchmark_Encode_SmallStructCached_GoJson(b *testing.B) {
cached := NewSmallPayload() cached := NewSmallPayload()
b.ReportAllocs() 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) { func Benchmark_Encode_MediumStruct_GoJson(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { 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) { func Benchmark_Encode_MediumStructCached_GoJson(b *testing.B) {
cached := NewMediumPayload() cached := NewMediumPayload()
b.ReportAllocs() 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) { func Benchmark_Encode_LargeStruct_GoJson(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { 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) { func Benchmark_Encode_LargeStructCached_GoJson(b *testing.B) {
cached := NewLargePayload() cached := NewLargePayload()
b.ReportAllocs() b.ReportAllocs()