@@ -38,7 +38,7 @@ static void BenchmarkRaw(benchmark::State& state) {
3838BENCHMARK (BenchmarkRaw);
3939
4040static void BenchmarkBasicModel (benchmark::State& state) {
41- casbin::Enforcer e (basic_model_path, basic_policy_path);
41+ casbin::Enforcer e (basic_model_path, basic_policy_path, false );
4242
4343 casbin::DataList params = {" alice" , " data1" , " read" };
4444
@@ -48,7 +48,7 @@ static void BenchmarkBasicModel(benchmark::State& state) {
4848BENCHMARK (BenchmarkBasicModel);
4949
5050static void BenchmarkRBACModel (benchmark::State& state) {
51- casbin::Enforcer e (rbac_model_path, rbac_policy_path);
51+ casbin::Enforcer e (rbac_model_path, rbac_policy_path, false );
5252
5353 casbin::DataList params = {" alice" , " data2" , " read" };
5454
@@ -57,6 +57,38 @@ static void BenchmarkRBACModel(benchmark::State& state) {
5757
5858BENCHMARK (BenchmarkRBACModel);
5959
60+ static void BenchmarkRBACModelSizesSmall (benchmark::State& state) {
61+ // 100, 10, 1000
62+ int num_roles = 100 , num_resources = 10 , num_users = 1000 ;
63+
64+ casbin::Enforcer e (rbac_model_path, " " , false );
65+
66+ for (int i = 0 ; i < num_roles; ++i) e.AddPolicy ({" group-has-a-very-long-name-" + std::to_string (i), " data-has-a-very-long-name-" + std::to_string (i % num_resources), " read" });
67+
68+ for (int i = 0 ; i < num_users; ++i) {
69+ e.AddGroupingPolicy ({" user-has-a-very-long-name-" + std::to_string (i), " group-has-a-very-long-name-" + std::to_string (i % num_roles)});
70+ }
71+
72+ int num_request = 17 ;
73+ std::vector<casbin::DataList> requests (num_request);
74+
75+ for (int i = 0 ; i < num_request; ++i) {
76+ int id_user = num_users / num_request * i,
77+ id_role = id_user / num_roles,
78+ id_resource = id_role % num_resources;
79+ if (i&2 == 0 )
80+ id_resource = (id_resource + 1 ) % num_resources;
81+
82+ requests[i] = {" user-has-a-very-long-name-" + std::to_string (id_user), " data-has-a-very-long-name-" + std::to_string (id_resource), " read" };
83+ }
84+
85+ for (auto _ : state)
86+ for (auto & req: requests)
87+ e.Enforce (req);
88+ }
89+
90+ BENCHMARK (BenchmarkRBACModelSizesSmall);
91+
6092static void BenchmarkRBACModelSmall (benchmark::State& state) {
6193 casbin::Enforcer e (rbac_model_path);
6294
@@ -73,7 +105,7 @@ static void BenchmarkRBACModelSmall(benchmark::State& state) {
73105BENCHMARK (BenchmarkRBACModelSmall);
74106
75107static void BenchmarkRBACModelWithResourceRoles (benchmark::State& state) {
76- casbin::Enforcer e (rbac_with_resource_roles_model_path, rbac_with_resource_roles_policy_path);
108+ casbin::Enforcer e (rbac_with_resource_roles_model_path, rbac_with_resource_roles_policy_path, false );
77109
78110 casbin::DataList params = {" alice" , " data1" , " read" };
79111 for (auto _ : state) e.Enforce (params);
@@ -82,7 +114,7 @@ static void BenchmarkRBACModelWithResourceRoles(benchmark::State& state) {
82114BENCHMARK (BenchmarkRBACModelWithResourceRoles);
83115
84116static void BenchmarkRBACModelWithDomains (benchmark::State& state) {
85- casbin::Enforcer e (rbac_with_domains_model_path, rbac_with_domains_policy_path);
117+ casbin::Enforcer e (rbac_with_domains_model_path, rbac_with_domains_policy_path, false );
86118 casbin::DataList params = {" alice" , " domain1" , " data1" , " read" };
87119
88120 for (auto _ : state) e.Enforce (params);
@@ -100,8 +132,19 @@ BENCHMARK(BenchmarkRBACModelWithDomains);
100132// }
101133// }
102134
135+ // ------ TODO ------
136+ // static void BenchmarkABACRuleModel(benchmark::State& state) {
137+ // casbin::Enforcer e("examples/abac_model.conf")
138+ // data1 := newTestResource("data1", "alice")
139+
140+ // for(auto _ : state) {
141+ // _, _ = e.Enforce("alice", data1, "read")
142+ // }
143+ // }
144+
145+
103146static void BenchmarkKeyMatchModel (benchmark::State& state) {
104- casbin::Enforcer e (keymatch_model_path, keymatch_policy_path);
147+ casbin::Enforcer e (keymatch_model_path, keymatch_policy_path, false );
105148 casbin::DataList params = {" alice" , " /alice_data/resource1" , " GET" };
106149
107150 for (auto _ : state) e.Enforce (params);
@@ -110,7 +153,7 @@ static void BenchmarkKeyMatchModel(benchmark::State& state) {
110153BENCHMARK (BenchmarkKeyMatchModel);
111154
112155static void BenchmarkRBACModelWithDeny (benchmark::State& state) {
113- casbin::Enforcer e (rbac_with_deny_model_path, rbac_with_deny_policy_path);
156+ casbin::Enforcer e (rbac_with_deny_model_path, rbac_with_deny_policy_path, false );
114157 casbin::DataList params = {" alice" , " data1" , " read" };
115158
116159 for (auto _ : state) e.Enforce (params);
@@ -119,7 +162,7 @@ static void BenchmarkRBACModelWithDeny(benchmark::State& state) {
119162BENCHMARK (BenchmarkRBACModelWithDeny);
120163
121164static void BenchmarkPriorityModel (benchmark::State& state) {
122- casbin::Enforcer e (priority_model_path, priority_policy_path);
165+ casbin::Enforcer e (priority_model_path, priority_policy_path, false );
123166 casbin::DataList params = {" alice" , " data1" , " read" };
124167
125168 for (auto _ : state) e.Enforce (params);
0 commit comments