Skip to content

Commit 0da8958

Browse files
committed
feat: added model_b.cpp to build system
Signed-off-by: Yash Pandey (YP) <[email protected]>
1 parent 5cd74e2 commit 0da8958

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

tests/benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
add_executable(casbin_benchmark
1616
config_path.h
1717
main.cpp
18+
model_b.cpp
1819
enforcer_cached_b.cpp
1920
management_api_b.cpp
2021
role_manager_b.cpp

tests/benchmarks/model_b.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ BENCHMARK(BenchmarkRaw);
3939

4040
static void BenchmarkBasicModel(benchmark::State& state) {
4141
casbin::Enforcer e(basic_model_path, basic_policy_path);
42-
std::vector<std::string> params = {"alice", "data1", "read"};
42+
casbin::DataList params = {"alice", "data1", "read"};
4343

4444
for(auto _ : state)
4545
e.Enforce(params);
@@ -50,7 +50,7 @@ BENCHMARK(BenchmarkBasicModel);
5050
static void BenchmarkRBACModel(benchmark::State& state) {
5151
casbin::Enforcer e(rbac_model_path, rbac_policy_path);
5252

53-
std::vector<std::string> params = {"alice", "data2", "read"};
53+
casbin::DataList params = {"alice", "data2", "read"};
5454

5555
for (auto _ : state)
5656
e.Enforce(params);
@@ -60,17 +60,16 @@ BENCHMARK(BenchmarkRBACModel);
6060

6161
static void BenchmarkRBACModelSmall(benchmark::State& state) {
6262
casbin::Enforcer e(rbac_model_path);
63-
std::vector<std::string> params(3);
6463

6564
// 100 roles, 10 resources.
6665
for(int i = 0; i < 100; ++i)
67-
params = { "group" + std::to_string(i), "data" + std::to_string(i/10), "read" }, e.AddPolicy(params);
66+
e.AddPolicy({ "group" + std::to_string(i), "data" + std::to_string(i/10), "read" });
6867

6968
// 1000 users.
7069
for(int i = 0; i < 1000; ++i)
71-
params = { "user" + std::to_string(i), "group" + std::to_string(i / 10) }, e.AddGroupingPolicy(params);
70+
e.AddGroupingPolicy({ "user" + std::to_string(i), "group" + std::to_string(i / 10) });
7271

73-
params = {"user501", "data9", "read"};
72+
casbin::DataList params = {"user501", "data9", "read"};
7473
for (auto _ : state)
7574
e.Enforce(params);
7675
}
@@ -79,38 +78,34 @@ BENCHMARK(BenchmarkRBACModelSmall);
7978

8079
static void BenchmarkRBACModelMedium(benchmark::State& state) {
8180
casbin::Enforcer e(rbac_model_path);
82-
std::vector<std::string> params(3);
8381

8482
// 1000 roles, 100 resources.
8583
for (int i = 0; i < 1000; ++i)
86-
params = {"group" + std::to_string(i), "data" + std::to_string(i / 10), "read"}, e.AddPolicy(params);
84+
e.AddPolicy({"group" + std::to_string(i), "data" + std::to_string(i / 10), "read"});
8785

8886
// 10000 users.
8987
for (int i = 0; i < 10000; ++i)
90-
params = {"user" + std::to_string(i), "group" + std::to_string(i / 10)}, e.AddGroupingPolicy(params);
88+
e.AddGroupingPolicy({"user" + std::to_string(i), "group" + std::to_string(i / 10)});
9189

92-
params = {"user5001", "data99", "read"};
90+
casbin::DataList params = {"user5001", "data99", "read"};
9391
for (auto _ : state)
9492
e.Enforce(params);
9593
}
9694

9795
BENCHMARK(BenchmarkRBACModelMedium);
9896

9997
static void BenchmarkRBACModelLarge(benchmark::State& state) {
100-
10198
casbin::Enforcer e(rbac_model_path);
102-
std::vector<std::string> params(3);
103-
std::vector<std::string> params2(2);
10499

105100
// 10000 roles, 1000 resources.
106101
for(int i = 0; i < 10000; ++i)
107-
params = {"group" + std::to_string(i), "data" + std::to_string(i / 10), "read"}, e.AddPolicy(params);
102+
e.AddPolicy({"group" + std::to_string(i), "data" + std::to_string(i / 10), "read"});
108103

109104
// 100000 users.
110105
for(int i = 0; i < 100000; i++)
111-
params2 = {"user" + std::to_string(i), "group" + std::to_string(i / 10)}, e.AddGroupingPolicy(params2);
106+
e.AddGroupingPolicy({"user" + std::to_string(i), "group" + std::to_string(i / 10)});
112107

113-
params = {"user50001", "data999", "read"};
108+
casbin::DataList params = {"user50001", "data999", "read"};
114109

115110
for(auto _ : state)
116111
e.Enforce(params);
@@ -120,9 +115,7 @@ static void BenchmarkRBACModelLarge(benchmark::State& state) {
120115

121116
static void BenchmarkRBACModelWithResourceRoles(benchmark::State& state) {
122117
casbin::Enforcer e(rbac_with_resource_roles_model_path, rbac_with_resource_roles_policy_path);
123-
std::vector<std::string> params(3);
124-
125-
params = {"alice", "data1", "read"};
118+
casbin::DataList params = {"alice", "data1", "read"};
126119
for (auto _ : state)
127120
e.Enforce(params);
128121
}
@@ -131,7 +124,7 @@ static void BenchmarkRBACModelWithResourceRoles(benchmark::State& state) {
131124

132125
static void BenchmarkRBACModelWithDomains(benchmark::State& state) {
133126
casbin::Enforcer e(rbac_with_domains_model_path, rbac_with_domains_policy_path);
134-
std::vector<std::string> params = {"alice", "domain1", "data1", "read"};
127+
casbin::DataList params = {"alice", "domain1", "data1", "read"};
135128

136129
for(auto _ : state)
137130
e.Enforce(params);
@@ -152,7 +145,7 @@ BENCHMARK(BenchmarkRBACModelWithDomains);
152145

153146
static void BenchmarkKeyMatchModel(benchmark::State& state) {
154147
casbin::Enforcer e(keymatch_model_path, keymatch_policy_path);
155-
std::vector<std::string> params = {"alice", "/alice_data/resource1", "GET"};
148+
casbin::DataList params = {"alice", "/alice_data/resource1", "GET"};
156149

157150
for (auto _ : state)
158151
e.Enforce(params);
@@ -162,7 +155,7 @@ BENCHMARK(BenchmarkKeyMatchModel);
162155

163156
static void BenchmarkRBACModelWithDeny(benchmark::State& state) {
164157
casbin::Enforcer e(rbac_with_deny_model_path, rbac_with_deny_policy_path);
165-
std::vector<std::string> params = {"alice", "data1", "read"};
158+
casbin::DataList params = {"alice", "data1", "read"};
166159

167160
for(auto _ : state)
168161
e.Enforce(params);
@@ -172,7 +165,7 @@ BENCHMARK(BenchmarkRBACModelWithDeny);
172165

173166
static void BenchmarkPriorityModel(benchmark::State& state) {
174167
casbin::Enforcer e(priority_model_path, priority_policy_path);
175-
std::vector<std::string> params = {"alice", "data1", "read"};
168+
casbin::DataList params = {"alice", "data1", "read"};
176169

177170
for(auto _ : state)
178171
e.Enforce(params);

0 commit comments

Comments
 (0)