(b *testing.B)
| 1219 | } |
| 1220 | |
| 1221 | func BenchmarkLargeHostMatcher(b *testing.B) { |
| 1222 | // this benchmark simulates a large host matcher (thousands of entries) where each |
| 1223 | // value is an exact hostname (not a placeholder or wildcard) - compare the results |
| 1224 | // of this with and without the binary search (comment out the various fast path |
| 1225 | // sections in Match) to conduct experiments |
| 1226 | |
| 1227 | const n = 10000 |
| 1228 | lastHost := fmt.Sprintf("%d.example.com", n-1) |
| 1229 | req := &http.Request{Host: lastHost} |
| 1230 | repl := caddy.NewReplacer() |
| 1231 | ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl) |
| 1232 | req = req.WithContext(ctx) |
| 1233 | |
| 1234 | matcher := make(MatchHost, n) |
| 1235 | for i := 0; i < n; i++ { |
| 1236 | matcher[i] = fmt.Sprintf("%d.example.com", i) |
| 1237 | } |
| 1238 | err := matcher.Provision(caddy.Context{}) |
| 1239 | if err != nil { |
| 1240 | b.Fatal(err) |
| 1241 | } |
| 1242 | |
| 1243 | for b.Loop() { |
| 1244 | matcher.MatchWithError(req) |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | func BenchmarkHostMatcherWithoutPlaceholder(b *testing.B) { |
| 1249 | req := &http.Request{Host: "localhost"} |
nothing calls this directly
no test coverage detected