@@ -0,0 +1,75 @@
9+ "github.com/oauth2-proxy/oauth2-proxy/pkg/apis/options"
12+var result AuthorizationPolicy
14+func benchmarkRuleSetMatches(ruleCount int, b *testing.B) {
15+ rule1 := options.AuthorizationRule{
16+ Policy: options.AllowPolicy,
17+ Path: "/[a-z]*/[a-z]*/[a-z]*",
42+ requestRules := options.RequestRules{}
43+ for i := 0; i <= ruleCount; i++ {
44+ requestRules = append(requestRules, rule1)
47+ ruleSet, err := NewRuleSet(requestRules, func(_ *http.Request) net.IP {
48+ return net.IPv4(192, 168, 0, 1)
54+ req := httptest.NewRequest("GET", "/foo/bar/baz", nil)
56+ var r AuthorizationPolicy
57+ for n := 0; n < b.N; n++ {
58+ r = ruleSet.Matches(req)
60+ b.Fatal("expected policy not to match")
63+ // always store the result to a package level variable
64+ // so the compiler cannot eliminate the Benchmark itself.
68+func BenchmarkRuleSetMatches1(b *testing.B) { benchmarkRuleSetMatches(1, b) }
69+func BenchmarkRuleSetMatches10(b *testing.B) { benchmarkRuleSetMatches(10, b) }
70+func BenchmarkRuleSetMatches25(b *testing.B) { benchmarkRuleSetMatches(25, b) }
71+func BenchmarkRuleSetMatches50(b *testing.B) { benchmarkRuleSetMatches(50, b) }
72+func BenchmarkRuleSetMatches100(b *testing.B) { benchmarkRuleSetMatches(100, b) }
73+func BenchmarkRuleSetMatches250(b *testing.B) { benchmarkRuleSetMatches(250, b) }
74+func BenchmarkRuleSetMatches500(b *testing.B) { benchmarkRuleSetMatches(500, b) }
75+func BenchmarkRuleSetMatches1000(b *testing.B) { benchmarkRuleSetMatches(1000, b) }