summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/matchers_test.go')
-rw-r--r--modules/caddyhttp/matchers_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index 51db67d..ab4487d 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -1018,6 +1018,33 @@ func TestNotMatcher(t *testing.T) {
}
}
}
+func BenchmarkLargeHostMatcher(b *testing.B) {
+ // this benchmark simulates a large host matcher (thousands of entries) where each
+ // value is an exact hostname (not a placeholder or wildcard) - compare the results
+ // of this with and without the binary search (comment out the various fast path
+ // sections in Match) to conduct experiments
+
+ const n = 10000
+ lastHost := fmt.Sprintf("%d.example.com", n-1)
+ req := &http.Request{Host: lastHost}
+ repl := caddy.NewReplacer()
+ ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
+ req = req.WithContext(ctx)
+
+ matcher := make(MatchHost, n)
+ for i := 0; i < n; i++ {
+ matcher[i] = fmt.Sprintf("%d.example.com", i)
+ }
+ err := matcher.Provision(caddy.Context{})
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ matcher.Match(req)
+ }
+}
func BenchmarkHostMatcherWithoutPlaceholder(b *testing.B) {
req := &http.Request{Host: "localhost"}