From 97020a9ad70e38f3160a72117cc055f6c9802652 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Thu, 1 Apr 2021 18:44:12 +0900 Subject: [PATCH] Add benchmark for testing #171 --- benchmarks/decode_large_test.go | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 benchmarks/decode_large_test.go diff --git a/benchmarks/decode_large_test.go b/benchmarks/decode_large_test.go new file mode 100644 index 0000000..3586f69 --- /dev/null +++ b/benchmarks/decode_large_test.go @@ -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) + } +}