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

Function BenchmarkRBACModelMedium

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

Source from the content-addressed store, hash-verified

150}
151
152func BenchmarkRBACModelMedium(b *testing.B) {
153 e, _ := NewEnforcer("examples/rbac_model.conf")
154
155 // 1000 roles, 100 resources.
156 pPolicies := make([][]string, 0)
157 for i := 0; i < 1000; i++ {
158 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
159 }
160
161 _, err := e.AddPolicies(pPolicies)
162 if err != nil {
163 b.Fatal(err)
164 }
165
166 // 10000 users.
167 gPolicies := make([][]string, 0)
168 for i := 0; i < 10000; i++ {
169 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
170 }
171
172 _, err = e.AddGroupingPolicies(gPolicies)
173 if err != nil {
174 b.Fatal(err)
175 }
176
177 b.ResetTimer()
178 for i := 0; i < b.N; i++ {
179 _, _ = e.Enforce("user5001", "data99", "read")
180 }
181}
182
183func BenchmarkRBACModelLarge(b *testing.B) {
184 e, _ := NewEnforcer("examples/rbac_model.conf")

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…