MCPcopy Index your code
hub / github.com/apache/casbin / BenchmarkRBACModelLarge

Function BenchmarkRBACModelLarge

model_b_test.go:183–212  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

181}
182
183func BenchmarkRBACModelLarge(b *testing.B) {
184 e, _ := NewEnforcer("examples/rbac_model.conf")
185
186 // 10000 roles, 1000 resources.
187 pPolicies := make([][]string, 0)
188 for i := 0; i < 10000; i++ {
189 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
190 }
191
192 _, err := e.AddPolicies(pPolicies)
193 if err != nil {
194 b.Fatal(err)
195 }
196
197 // 100000 users.
198 gPolicies := make([][]string, 0)
199 for i := 0; i < 100000; i++ {
200 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
201 }
202
203 _, err = e.AddGroupingPolicies(gPolicies)
204 if err != nil {
205 b.Fatal(err)
206 }
207
208 b.ResetTimer()
209 for i := 0; i < b.N; i++ {
210 _, _ = e.Enforce("user50001", "data999", "read")
211 }
212}
213
214func BenchmarkRBACModelWithResourceRoles(b *testing.B) {
215 e, _ := NewEnforcer("examples/rbac_with_resource_roles_model.conf", "examples/rbac_with_resource_roles_policy.csv")

Callers

nothing calls this directly

Calls 4

AddPoliciesMethod · 0.95
AddGroupingPoliciesMethod · 0.95
EnforceMethod · 0.95
NewEnforcerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…