Skip to content

Commit

Permalink
test(middleware/cors): Add benchmark for CORS subdomain matching
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Mar 18, 2024
1 parent 7475036 commit 2da3df1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions middleware/cors/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 2da3df1

Please sign in to comment.