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

Function BenchmarkHasPolicySmall

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

Source from the content-addressed store, hash-verified

20)
21
22func BenchmarkHasPolicySmall(b *testing.B) {
23 e, _ := NewEnforcer("examples/basic_model.conf")
24
25 // 100 roles, 10 resources.
26 for i := 0; i < 100; i++ {
27 _, _ = e.AddPolicy(fmt.Sprintf("user%d", i), fmt.Sprintf("data%d", i/10), "read")
28 }
29
30 b.ResetTimer()
31 for i := 0; i < b.N; i++ {
32 e.HasPolicy(fmt.Sprintf("user%d", rand.Intn(100)), fmt.Sprintf("data%d", rand.Intn(100)/10), "read")
33 }
34}
35
36func BenchmarkHasPolicyMedium(b *testing.B) {
37 e, _ := NewEnforcer("examples/basic_model.conf")

Callers

nothing calls this directly

Calls 3

AddPolicyMethod · 0.95
HasPolicyMethod · 0.95
NewEnforcerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…