From 62b28d102edcdb70a1b46fd246e16c11f88dcc71 Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Sat, 12 Feb 2022 17:55:10 +0900 Subject: [PATCH] test: add benchmark --- benchmarks/decode_test.go | 10 ++++++++++ benchmarks/large_payload.go | 3 +++ 2 files changed, 13 insertions(+) diff --git a/benchmarks/decode_test.go b/benchmarks/decode_test.go index 0626219..5f2a4c2 100644 --- a/benchmarks/decode_test.go +++ b/benchmarks/decode_test.go @@ -477,3 +477,13 @@ func Benchmark_Decode_LargeStruct_Stream_GoJsonFirstWinMode(b *testing.B) { } } } + +func Benchmark_Decode_LargeSlice_EscapedString_GoJson(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + var v []string + if err := gojson.Unmarshal(LargeSliceEscapedString, &v); err != nil { + b.Fatal(err) + } + } +} diff --git a/benchmarks/large_payload.go b/benchmarks/large_payload.go index f6d1c1a..42d8621 100644 --- a/benchmarks/large_payload.go +++ b/benchmarks/large_payload.go @@ -2,6 +2,7 @@ package benchmark import ( "strconv" + "strings" "github.com/francoispqt/gojay" ) @@ -208,3 +209,5 @@ func NewLargePayloadEasyJson() *LargePayloadEasyJson { }, } } + +var LargeSliceEscapedString = []byte("[" + strings.Repeat(",\"simple plain text\\r\\n\"", 10000)[1:] + "]")