From 856d3c632fe5a35989d6ed699306152e6c961f07 Mon Sep 17 00:00:00 2001 From: Steve McDaniel Date: Sun, 18 Feb 2024 20:17:19 -0700 Subject: [PATCH] add benchmark for JSONPointerToSlice cache --- gabs_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gabs_test.go b/gabs_test.go index f8429e5..29506d2 100644 --- a/gabs_test.go +++ b/gabs_test.go @@ -1950,3 +1950,37 @@ func BenchmarkWildcardSearch(b *testing.B) { val.Search([]string{"test", "*", "value"}...) } } + +func BenchmarkJsonPointerToSlice(b *testing.B) { + samples := []string{ + "/test/field", + "/field/test", + "/user/name", + "/user/email/address", + "/host/ip/addres", + "/host/os/family", + "/host/os/version", + "/test/field", + "/field/test", + "/user/name", + "/user/email/address", + "/host/ip/addres", + "/host/os/family", + "/host/os/version", + "/test/field", + "/field/test", + "/user/name", + "/user/email/address", + "/host/ip/addres", + "/host/os/family", + "/host/os/version", + } + b.ReportAllocs() + b.ResetTimer() + + for i := 0; i < b.N; i++ { + for _, s := range samples { + JSONPointerToSlice(s) + } + } +}