From a374266ec3c6e182b43d4432a0fa6083eb13845b Mon Sep 17 00:00:00 2001 From: Joe Higton Date: Sun, 7 Aug 2022 11:13:50 +0100 Subject: [PATCH] [json] add a benchmark to help check new scan for key --- internal/json/scanner_bench_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 internal/json/scanner_bench_test.go diff --git a/internal/json/scanner_bench_test.go b/internal/json/scanner_bench_test.go new file mode 100644 index 0000000..e5a9c35 --- /dev/null +++ b/internal/json/scanner_bench_test.go @@ -0,0 +1,28 @@ +package json + +import ( + "testing" +) + +var input = []byte( + ` + "alpha" : { + "zeeta" : [1,2,3,4,5,6,7,8,9,10], + "cheese" : "cake", + }, + "cheesy" : 1, + "cheese": 4 +} +`, +) + +func BenchmarkScanForKey(b *testing.B) { + for n := 0; n < b.N; n++ { + s := NewScanState('{') + s.seekFor("cheese") + _, err := s.scan(input, 0, len(input)) + if err != nil { + b.Fatal(err) + } + } +}