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

Function BenchmarkRoleManagerLarge

role_manager_b_test.go:88–121  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

86}
87
88func BenchmarkRoleManagerLarge(b *testing.B) {
89 e, _ := NewEnforcer("examples/rbac_model.conf")
90
91 // 10000 roles, 1000 resources.
92 pPolicies := make([][]string, 0)
93 for i := 0; i < 10000; i++ {
94 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
95 }
96
97 _, err := e.AddPolicies(pPolicies)
98 if err != nil {
99 b.Fatal(err)
100 }
101
102 // 100000 users.
103 gPolicies := make([][]string, 0)
104 for i := 0; i < 100000; i++ {
105 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
106 }
107
108 _, err = e.AddGroupingPolicies(gPolicies)
109 if err != nil {
110 b.Fatal(err)
111 }
112
113 rm := e.GetRoleManager()
114
115 b.ResetTimer()
116 for i := 0; i < b.N; i++ {
117 for j := 0; j < 10000; j++ {
118 _, _ = rm.HasLink("user501", fmt.Sprintf("group%d", j))
119 }
120 }
121}
122
123func BenchmarkBuildRoleLinksWithPatternLarge(b *testing.B) {
124 e, _ := NewEnforcer("examples/performance/rbac_with_pattern_large_scale_model.conf", "examples/performance/rbac_with_pattern_large_scale_policy.csv")

Callers

nothing calls this directly

Calls 5

AddPoliciesMethod · 0.95
AddGroupingPoliciesMethod · 0.95
GetRoleManagerMethod · 0.95
NewEnforcerFunction · 0.85
HasLinkMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…