diff --git a/tests/benchmarks/CMakeLists.txt b/tests/benchmarks/CMakeLists.txt index 31f13e17..483b0453 100644 --- a/tests/benchmarks/CMakeLists.txt +++ b/tests/benchmarks/CMakeLists.txt @@ -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 diff --git a/tests/benchmarks/model_b.cpp b/tests/benchmarks/model_b.cpp index ab9276fd..e603e8d9 100644 --- a/tests/benchmarks/model_b.cpp +++ b/tests/benchmarks/model_b.cpp @@ -39,7 +39,7 @@ BENCHMARK(BenchmarkRaw); static void BenchmarkBasicModel(benchmark::State& state) { casbin::Enforcer e(basic_model_path, basic_policy_path); - std::vector params = {"alice", "data1", "read"}; + casbin::DataList params = {"alice", "data1", "read"}; for(auto _ : state) e.Enforce(params); @@ -50,7 +50,7 @@ BENCHMARK(BenchmarkBasicModel); static void BenchmarkRBACModel(benchmark::State& state) { casbin::Enforcer e(rbac_model_path, rbac_policy_path); - std::vector params = {"alice", "data2", "read"}; + casbin::DataList params = {"alice", "data2", "read"}; for (auto _ : state) e.Enforce(params); @@ -60,17 +60,16 @@ BENCHMARK(BenchmarkRBACModel); static void BenchmarkRBACModelSmall(benchmark::State& state) { casbin::Enforcer e(rbac_model_path); - std::vector 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); } @@ -79,17 +78,16 @@ BENCHMARK(BenchmarkRBACModelSmall); static void BenchmarkRBACModelMedium(benchmark::State& state) { casbin::Enforcer e(rbac_model_path); - std::vector 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); } @@ -97,20 +95,17 @@ static void BenchmarkRBACModelMedium(benchmark::State& state) { BENCHMARK(BenchmarkRBACModelMedium); static void BenchmarkRBACModelLarge(benchmark::State& state) { - casbin::Enforcer e(rbac_model_path); - std::vector params(3); - std::vector 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); @@ -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 params(3); - - params = {"alice", "data1", "read"}; + casbin::DataList params = {"alice", "data1", "read"}; for (auto _ : state) e.Enforce(params); } @@ -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 params = {"alice", "domain1", "data1", "read"}; + casbin::DataList params = {"alice", "domain1", "data1", "read"}; for(auto _ : state) e.Enforce(params); @@ -152,7 +145,7 @@ BENCHMARK(BenchmarkRBACModelWithDomains); static void BenchmarkKeyMatchModel(benchmark::State& state) { casbin::Enforcer e(keymatch_model_path, keymatch_policy_path); - std::vector params = {"alice", "/alice_data/resource1", "GET"}; + casbin::DataList params = {"alice", "/alice_data/resource1", "GET"}; for (auto _ : state) e.Enforce(params); @@ -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 params = {"alice", "data1", "read"}; + casbin::DataList params = {"alice", "data1", "read"}; for(auto _ : state) e.Enforce(params); @@ -172,7 +165,7 @@ BENCHMARK(BenchmarkRBACModelWithDeny); static void BenchmarkPriorityModel(benchmark::State& state) { casbin::Enforcer e(priority_model_path, priority_policy_path); - std::vector params = {"alice", "data1", "read"}; + casbin::DataList params = {"alice", "data1", "read"}; for(auto _ : state) e.Enforce(params);