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

Function BenchmarkCachedRBACModelMedium

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

Source from the content-addressed store, hash-verified

67}
68
69func BenchmarkCachedRBACModelMedium(b *testing.B) {
70 e, _ := NewCachedEnforcer("examples/rbac_model.conf")
71 // 1000 roles, 100 resources.
72 pPolicies := make([][]string, 0)
73 for i := 0; i < 1000; i++ {
74 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
75 }
76
77 _, err := e.AddPolicies(pPolicies)
78 if err != nil {
79 b.Fatal(err)
80 }
81
82 // 10000 users.
83 gPolicies := make([][]string, 0)
84 for i := 0; i < 10000; i++ {
85 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
86 }
87
88 _, err = e.AddGroupingPolicies(gPolicies)
89 if err != nil {
90 b.Fatal(err)
91 }
92
93 b.ResetTimer()
94 for i := 0; i < b.N; i++ {
95 _, _ = e.Enforce("user5001", "data150", "read")
96 }
97}
98
99func BenchmarkCachedRBACModelLarge(b *testing.B) {
100 e, _ := NewCachedEnforcer("examples/rbac_model.conf")

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…