Add benchmark for testing #171

This commit is contained in:
Masaaki Goshima 2021-04-01 18:44:12 +09:00
parent 7d4316b94a
commit 97020a9ad7
1 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package benchmark
import (
"encoding/json"
"io/ioutil"
"testing"
gojson "github.com/goccy/go-json"
)
type coordinate struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
Name string `json:"name"`
Opts map[string]interface{} `json:"opts"`
}
type testStruct struct {
Coordinates []coordinate `json:"coordinates"`
}
func Benchmark_DecodeHugeDataGoJSON(b *testing.B) {
dat, err := ioutil.ReadFile("./bench.json")
if err != nil {
b.Fatal(err)
}
b.ReportAllocs()
jobj := testStruct{}
if err := gojson.Unmarshal(dat, &jobj); err != nil {
b.Fatal(err)
}
}
func Benchmark_DecodeHugeDataEncodingJSON(b *testing.B) {
dat, err := ioutil.ReadFile("./bench.json")
if err != nil {
b.Fatal(err)
}
b.ReportAllocs()
jobj := testStruct{}
if err := json.Unmarshal(dat, &jobj); err != nil {
b.Fatal(err)
}
}