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

Function BenchmarkAddPolicyLarge

management_api_b_test.go:105–122  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

103}
104
105func BenchmarkAddPolicyLarge(b *testing.B) {
106 e, _ := NewEnforcer("examples/basic_model.conf")
107
108 // 10000 roles, 1000 resources.
109 pPolicies := make([][]string, 0)
110 for i := 0; i < 10000; i++ {
111 pPolicies = append(pPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("data%d", i/10), "read"})
112 }
113 _, err := e.AddPolicies(pPolicies)
114 if err != nil {
115 b.Fatal(err)
116 }
117
118 b.ResetTimer()
119 for i := 0; i < b.N; i++ {
120 _, _ = e.AddPolicy(fmt.Sprintf("user%d", rand.Intn(10000)+10000), fmt.Sprintf("data%d", (rand.Intn(10000)+10000)/10), "read")
121 }
122}
123
124func BenchmarkRemovePolicySmall(b *testing.B) {
125 e, _ := NewEnforcer("examples/basic_model.conf")

Callers

nothing calls this directly

Calls 3

AddPoliciesMethod · 0.95
AddPolicyMethod · 0.95
NewEnforcerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…