Add benchmark for Compact/Indent

This commit is contained in:
Masaaki Goshima 2021-04-19 20:29:41 +09:00
parent 34396640d5
commit 7dd33b9060
1 changed files with 60 additions and 0 deletions

View File

@ -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)
}
}
}