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

Function BenchmarkAddPolicyMedium

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

Source from the content-addressed store, hash-verified

85}
86
87func BenchmarkAddPolicyMedium(b *testing.B) {
88 e, _ := NewEnforcer("examples/basic_model.conf")
89
90 // 1000 roles, 100 resources.
91 pPolicies := make([][]string, 0)
92 for i := 0; i < 1000; i++ {
93 pPolicies = append(pPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("data%d", i/10), "read"})
94 }
95 _, err := e.AddPolicies(pPolicies)
96 if err != nil {
97 b.Fatal(err)
98 }
99 b.ResetTimer()
100 for i := 0; i < b.N; i++ {
101 _, _ = e.AddPolicy(fmt.Sprintf("user%d", rand.Intn(1000)+1000), fmt.Sprintf("data%d", (rand.Intn(1000)+1000)/10), "read")
102 }
103}
104
105func BenchmarkAddPolicyLarge(b *testing.B) {
106 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…