From fd6c77cab6096b5bf6c5457cf000a2a2f1422e0b Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Thu, 7 Nov 2024 10:29:13 +0530 Subject: [PATCH] Add benchmark + Get --- internal/collections/map_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/collections/map_test.go b/internal/collections/map_test.go index 68bb83c42..d7d1a38eb 100644 --- a/internal/collections/map_test.go +++ b/internal/collections/map_test.go @@ -16,6 +16,7 @@ package collections import ( "fmt" "regexp" + "strconv" "testing" "github.com/corazawaf/coraza/v3/types/variables" @@ -106,3 +107,14 @@ func TestNewCaseSensitiveKeyMap(t *testing.T) { } } + +func BenchmarkTxGet(b *testing.B) { + c := NewCaseSensitiveKeyMap(variables.RequestHeaders) + for i := 0; i < b.N; i++ { + c.Set("key"+strconv.Itoa(i), []string{"value1", "value2"}) + } + // Benchmark the Get method + for i := 0; i < b.N; i++ { + c.Get("key500") + } +}