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

Function BenchmarkHasPolicyMedium

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

Source from the content-addressed store, hash-verified

34}
35
36func BenchmarkHasPolicyMedium(b *testing.B) {
37 e, _ := NewEnforcer("examples/basic_model.conf")
38
39 // 1000 roles, 100 resources.
40 pPolicies := make([][]string, 0)
41 for i := 0; i < 1000; i++ {
42 pPolicies = append(pPolicies, []string{fmt.Sprintf("user%d", i), fmt.Sprintf("data%d", i/10), "read"})
43 }
44 _, err := e.AddPolicies(pPolicies)
45 if err != nil {
46 b.Fatal(err)
47 }
48 b.ResetTimer()
49 for i := 0; i < b.N; i++ {
50 e.HasPolicy(fmt.Sprintf("user%d", rand.Intn(1000)), fmt.Sprintf("data%d", rand.Intn(1000)/10), "read")
51 }
52}
53
54func BenchmarkHasPolicyLarge(b *testing.B) {
55 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…