Skip to content

Commit

Permalink
feat: added model_b.cpp to build system
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
  • Loading branch information
EmperorYP7 committed Jul 17, 2021
1 parent 5cd74e2 commit 0da8958
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions tests/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
add_executable(casbin_benchmark
config_path.h
main.cpp
model_b.cpp
enforcer_cached_b.cpp
management_api_b.cpp
role_manager_b.cpp
Expand Down
39 changes: 16 additions & 23 deletions tests/benchmarks/model_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BENCHMARK(BenchmarkRaw);

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

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

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

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

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

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

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

params = {"user501", "data9", "read"};
casbin::DataList params = {"user501", "data9", "read"};
for (auto _ : state)
e.Enforce(params);
}
Expand All @@ -79,38 +78,34 @@ BENCHMARK(BenchmarkRBACModelSmall);

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

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

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

params = {"user5001", "data99", "read"};
casbin::DataList params = {"user5001", "data99", "read"};
for (auto _ : state)
e.Enforce(params);
}

BENCHMARK(BenchmarkRBACModelMedium);

static void BenchmarkRBACModelLarge(benchmark::State& state) {

casbin::Enforcer e(rbac_model_path);
std::vector<std::string> params(3);
std::vector<std::string> params2(2);

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

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

params = {"user50001", "data999", "read"};
casbin::DataList params = {"user50001", "data999", "read"};

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

static void BenchmarkRBACModelWithResourceRoles(benchmark::State& state) {
casbin::Enforcer e(rbac_with_resource_roles_model_path, rbac_with_resource_roles_policy_path);
std::vector<std::string> params(3);

params = {"alice", "data1", "read"};
casbin::DataList params = {"alice", "data1", "read"};
for (auto _ : state)
e.Enforce(params);
}
Expand All @@ -131,7 +124,7 @@ static void BenchmarkRBACModelWithResourceRoles(benchmark::State& state) {

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

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

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

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

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

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

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

for(auto _ : state)
e.Enforce(params);
Expand Down

0 comments on commit 0da8958

Please sign in to comment.