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

Function BenchmarkRoleManagerSmall

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

Source from the content-addressed store, hash-verified

8)
9
10func BenchmarkRoleManagerSmall(b *testing.B) {
11 e, _ := NewEnforcer("examples/rbac_model.conf")
12 // Do not rebuild the role inheritance relations for every AddGroupingPolicy() call.
13 e.EnableAutoBuildRoleLinks(false)
14
15 // 100 roles, 10 resources.
16 pPolicies := make([][]string, 0)
17 for i := 0; i < 100; i++ {
18 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
19 }
20
21 _, err := e.AddPolicies(pPolicies)
22 if err != nil {
23 b.Fatal(err)
24 }
25
26 // 1000 users.
27 gPolicies := make([][]string, 0)
28 for i := 0; i < 1000; i++ {
29 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
30 }
31
32 _, err = e.AddGroupingPolicies(gPolicies)
33 if err != nil {
34 b.Fatal(err)
35 }
36
37 rm := e.GetRoleManager()
38
39 b.ResetTimer()
40 for i := 0; i < b.N; i++ {
41 for j := 0; j < 100; j++ {
42 _, _ = rm.HasLink("user501", fmt.Sprintf("group%d", j))
43 }
44 }
45}
46
47func BenchmarkRoleManagerMedium(b *testing.B) {
48 e, _ := NewEnforcer("examples/rbac_model.conf")

Callers

nothing calls this directly

Calls 6

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…