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

Function BenchmarkCachedRBACModelMediumParallel

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

Source from the content-addressed store, hash-verified

190}
191
192func BenchmarkCachedRBACModelMediumParallel(b *testing.B) {
193 e, _ := NewCachedEnforcer("examples/rbac_model.conf")
194
195 // 10000 roles, 1000 resources.
196 pPolicies := make([][]string, 0)
197 for i := 0; i < 10000; i++ {
198 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
199 }
200 _, err := e.AddPolicies(pPolicies)
201 if err != nil {
202 b.Fatal(err)
203 }
204
205 // 100000 users.
206 gPolicies := make([][]string, 0)
207 for i := 0; i < 100000; i++ {
208 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
209 }
210 _, err = e.AddGroupingPolicies(gPolicies)
211 if err != nil {
212 b.Fatal(err)
213 }
214
215 b.ResetTimer()
216 b.RunParallel(func(pb *testing.PB) {
217 for pb.Next() {
218 _, _ = e.Enforce("user5001", "data150", "read")
219 }
220 })
221}

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…