MCPcopy
hub / github.com/apache/casbin / BenchmarkCachedRBACModelLarge

Function BenchmarkCachedRBACModelLarge

enforcer_cached_b_test.go:99–126  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

97}
98
99func BenchmarkCachedRBACModelLarge(b *testing.B) {
100 e, _ := NewCachedEnforcer("examples/rbac_model.conf")
101
102 // 10000 roles, 1000 resources.
103 pPolicies := make([][]string, 0)
104 for i := 0; i < 10000; i++ {
105 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
106 }
107 _, err := e.AddPolicies(pPolicies)
108 if err != nil {
109 b.Fatal(err)
110 }
111
112 // 100000 users.
113 gPolicies := make([][]string, 0)
114 for i := 0; i < 100000; i++ {
115 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
116 }
117 _, err = e.AddGroupingPolicies(gPolicies)
118 if err != nil {
119 b.Fatal(err)
120 }
121
122 b.ResetTimer()
123 for i := 0; i < b.N; i++ {
124 _, _ = e.Enforce("user50001", "data1500", "read")
125 }
126}
127
128func BenchmarkCachedRBACModelWithResourceRoles(b *testing.B) {
129 e, _ := NewCachedEnforcer("examples/rbac_with_resource_roles_model.conf", "examples/rbac_with_resource_roles_policy.csv")

Callers

nothing calls this directly

Calls 4

EnforceMethod · 0.95
NewCachedEnforcerFunction · 0.85
AddPoliciesMethod · 0.65
AddGroupingPoliciesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…