From 7dd33b9060d6a65ba822aa12edd7c93138678087 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Mon, 19 Apr 2021 20:29:41 +0900 Subject: [PATCH] Add benchmark for Compact/Indent --- benchmarks/bench_test.go | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index e199620..d671811 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -581,3 +581,63 @@ func BenchmarkUnmapped(b *testing.B) { } }) } + +func Benchmark_Compact_EncodingJson(b *testing.B) { + b.ReportAllocs() + if codeJSON == nil { + b.StopTimer() + codeInit() + b.StartTimer() + } + for i := 0; i < b.N; i++ { + var buf bytes.Buffer + if err := stdjson.Compact(&buf, codeJSON); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Compact_GoJson(b *testing.B) { + b.ReportAllocs() + if codeJSON == nil { + b.StopTimer() + codeInit() + b.StartTimer() + } + for i := 0; i < b.N; i++ { + var buf bytes.Buffer + if err := json.Compact(&buf, codeJSON); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Indent_EncodingJson(b *testing.B) { + b.ReportAllocs() + if codeJSON == nil { + b.StopTimer() + codeInit() + b.StartTimer() + } + for i := 0; i < b.N; i++ { + var buf bytes.Buffer + if err := stdjson.Indent(&buf, codeJSON, "-", " "); err != nil { + b.Fatal(err) + } + } +} + +func Benchmark_Indent_GoJson(b *testing.B) { + b.ReportAllocs() + if codeJSON == nil { + b.StopTimer() + codeInit() + b.StartTimer() + } + for i := 0; i < b.N; i++ { + var buf bytes.Buffer + if err := json.Indent(&buf, codeJSON, "-", " "); err != nil { + b.Fatal(err) + } + } +}