From 2da3df1de2258fbf41a8d7fcaf39fe1f59491450 Mon Sep 17 00:00:00 2001 From: Jason McNeil Date: Mon, 18 Mar 2024 20:57:38 -0300 Subject: [PATCH] test(middleware/cors): Add benchmark for CORS subdomain matching --- middleware/cors/utils_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/middleware/cors/utils_test.go b/middleware/cors/utils_test.go index 40b8345fa7..2fe037a474 100644 --- a/middleware/cors/utils_test.go +++ b/middleware/cors/utils_test.go @@ -157,3 +157,20 @@ func TestSubdomainMatch(t *testing.T) { }) } } + +// go test -v -run=^$ -bench=Benchmark_CORS_SubdomainMatch -benchmem -count=4 +func Benchmark_CORS_SubdomainMatch(b *testing.B) { + s := subdomain{ + prefix: "www", + suffix: ".example.com", + } + + o := "www.example.com" + + b.ResetTimer() + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + s.match(o) + } +}