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

Function BenchmarkHasPolicyLarge

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

Source from the content-addressed store, hash-verified

52}
53
54func BenchmarkHasPolicyLarge(b *testing.B) {
55 e, _ := NewEnforcer("examples/basic_model.conf")
56
57 // 10000 roles, 1000 resources.
58 pPolicies := make([][]string, 0)
59 for i := 0; i < 10000; i++ {
60 pPolicies = append(pPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("data%d", i/10), "read"})
61 }
62 _, err := e.AddPolicies(pPolicies)
63 if err != nil {
64 b.Fatal(err)
65 }
66
67 b.ResetTimer()
68 for i := 0; i < b.N; i++ {
69 e.HasPolicy(fmt.Sprintf("user%d", rand.Intn(10000)), fmt.Sprintf("data%d", rand.Intn(10000)/10), "read")
70 }
71}
72
73func BenchmarkAddPolicySmall(b *testing.B) {
74 e, _ := NewEnforcer("examples/basic_model.conf")

Callers

nothing calls this directly

Calls 3

AddPoliciesMethod · 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…