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

Function BenchmarkRoleManagerMedium

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

Source from the content-addressed store, hash-verified

45}
46
47func BenchmarkRoleManagerMedium(b *testing.B) {
48 e, _ := NewEnforcer("examples/rbac_model.conf")
49 // Do not rebuild the role inheritance relations for every AddGroupingPolicy() call.
50 e.EnableAutoBuildRoleLinks(false)
51
52 // 1000 roles, 100 resources.
53 pPolicies := make([][]string, 0)
54 for i := 0; i < 1000; i++ {
55 pPolicies = append(pPolicies, []string{fmt.Sprintf("group%d", i), fmt.Sprintf("data%d", i/10), "read"})
56 }
57 _, err := e.AddPolicies(pPolicies)
58 if err != nil {
59 b.Fatal(err)
60 }
61
62 // 10000 users.
63 gPolicies := make([][]string, 0)
64 for i := 0; i < 10000; i++ {
65 gPolicies = append(gPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("group%d", i/10)})
66 }
67
68 _, err = e.AddGroupingPolicies(gPolicies)
69 if err != nil {
70 b.Fatal(err)
71 }
72
73 err = e.BuildRoleLinks()
74 if err != nil {
75 b.Fatal(err)
76 }
77
78 rm := e.GetRoleManager()
79
80 b.ResetTimer()
81 for i := 0; i < b.N; i++ {
82 for j := 0; j < 1000; j++ {
83 _, _ = rm.HasLink("user501", fmt.Sprintf("group%d", j))
84 }
85 }
86}
87
88func BenchmarkRoleManagerLarge(b *testing.B) {
89 e, _ := NewEnforcer("examples/rbac_model.conf")

Callers

nothing calls this directly

Calls 7

AddPoliciesMethod · 0.95
AddGroupingPoliciesMethod · 0.95
BuildRoleLinksMethod · 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…