-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: expedite benchmark tests #159
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ BENCHMARK(BenchmarkCachedRBACModel); | |
|
||
// BENCHMARK(BenchmarkCachedRaw); | ||
|
||
static void BenchmarkCachedRBACModelSmall(benchmark::State& state) { | ||
static void BenchmarkCachedRBACModelLoop(benchmark::State& state) { | ||
casbin::CachedEnforcer e(rbac_model_path, "", false); | ||
// 100 roles, 10 resources. | ||
for (int i = 0; i < 100; ++i) | ||
|
@@ -60,53 +60,7 @@ static void BenchmarkCachedRBACModelSmall(benchmark::State& state) { | |
e.Enforce(params); | ||
} | ||
|
||
BENCHMARK(BenchmarkCachedRBACModelSmall); | ||
|
||
static void BenchmarkCachedRBACModelMedium(benchmark::State& state) { | ||
casbin::CachedEnforcer e(rbac_model_path, "", false); | ||
std::vector<std::vector<std::string>> p_policies(1000); | ||
// 1000 roles, 100 resources. | ||
for (int i = 0; i < 1000; ++i) | ||
p_policies[i] = { "group" + std::to_string(i), "data" + std::to_string(i / 10), "read" }; | ||
|
||
e.AddPolicies(p_policies); | ||
|
||
// 10000 users. | ||
std::vector<std::vector<std::string>> g_policies(10000); | ||
for (int i = 0; i < 10000; ++i) | ||
g_policies[i] = { "user" + std::to_string(i), "group" + std::to_string(i/10) }; | ||
|
||
e.AddGroupingPolicies(g_policies); | ||
casbin::DataList params = {"user5001", "data150", "read"}; | ||
for (auto _ : state) | ||
e.Enforce(params); | ||
} | ||
|
||
// BENCHMARK(BenchmarkCachedRBACModelMedium); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise |
||
|
||
static void BenchmarkCachedRBACModelLarge(benchmark::State& state) { | ||
casbin::CachedEnforcer e(rbac_model_path, "", false); | ||
|
||
// 10000 roles, 1000 resources. | ||
std::vector<std::vector<std::string>> p_policies(10000); | ||
for (int i = 0; i < 10000; ++i) | ||
p_policies[i] = {"group", std::to_string(i), "data", std::to_string(i / 10), "read"}; | ||
e.AddPolicies(p_policies); | ||
|
||
// 100000 users. | ||
std::vector<std::vector<std::string>> g_policies(100000); | ||
for (int i = 0; i < 100000; ++i) { | ||
g_policies[i] = {"user" + std::to_string(i), "group", std::to_string(i / 10)}; | ||
} | ||
e.AddGroupingPolicies(g_policies); | ||
casbin::DataList params = {"user50001", "data1500", "read"}; | ||
for (auto _ : state) | ||
{ | ||
e.Enforce(params); | ||
} | ||
} | ||
|
||
// BENCHMARK(BenchmarkCachedRBACModelLarge); | ||
BENCHMARK(BenchmarkCachedRBACModelLoop); | ||
|
||
static void BenchmarkCachedRBACModelWithResourceRoles(benchmark::State& state) { | ||
casbin::CachedEnforcer e(rbac_with_resource_roles_model_path, rbac_with_resource_roles_policy_path, false); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ static void BenchmarkVectorOperations(benchmark::State& state) { | |
|
||
BENCHMARK(BenchmarkVectorOperations); | ||
|
||
static void BenchmarkHasPolicySmall(benchmark::State& state) { | ||
static void BenchmarkHasPolicyLoop(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 100 roles, 10 resources. | ||
|
@@ -60,37 +60,9 @@ static void BenchmarkHasPolicySmall(benchmark::State& state) { | |
params = { "user" + std::to_string(GetRandom100()), "data" + std::to_string(GetRandom100()/10), "read" }, e.HasPolicy(params); | ||
} | ||
|
||
BENCHMARK(BenchmarkHasPolicySmall); | ||
BENCHMARK(BenchmarkHasPolicyLoop); | ||
|
||
static void BenchmarkHasPolicyMedium(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 1000 roles, 100 resources. | ||
// std::vector<std::vector<std::string>> p_policies(1000); | ||
for (int i = 0; i < 1000; ++i) | ||
params = {"user" + std::to_string(i), "data" + std::to_string(i / 10), "read"}, e.AddPolicy(params); | ||
// e.AddPolicies(p_policies); | ||
for (auto _ : state) | ||
params = { "user" + std::to_string(GetRandom1000()), "data" + std::to_string(GetRandom1000()/10), "read" }, e.HasPolicy(params); | ||
} | ||
|
||
BENCHMARK(BenchmarkHasPolicyMedium); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise |
||
|
||
static void BenchmarkHasPolicyLarge(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 10000 roles, 1000 resources. | ||
for (int i = 0; i < 10000; i++) | ||
params = {"user" + std::to_string(i), "data" + std::to_string(i / 10), "read"}, e.AddPolicy(params); | ||
|
||
for(auto _ : state) { | ||
params = {"user" + std::to_string(GetRandom10000()), "data" + std::to_string(GetRandom10000()/10), "read"}, e.HasPolicy(params); | ||
} | ||
} | ||
|
||
BENCHMARK(BenchmarkHasPolicyLarge); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise |
||
|
||
static void BenchmarkAddPolicySmall(benchmark::State& state) { | ||
static void BenchmarkAddPolicyLoop(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 100 roles, 10 resources. | ||
|
@@ -101,38 +73,9 @@ static void BenchmarkAddPolicySmall(benchmark::State& state) { | |
params = {"user" + std::to_string(GetRandom100() + 100), "data" + std::to_string((GetRandom100() + 100)/10), "read"}, e.AddPolicy(params); | ||
} | ||
|
||
BENCHMARK(BenchmarkAddPolicySmall); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well |
||
|
||
static void BenchmarkAddPolicyMedium(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 1000 roles, 100 resources. | ||
for(int i = 0; i < 1000; ++i) | ||
params = {"user" + std::to_string(i), "data" + std::to_string(i / 10), "read"}, e.AddPolicy(params); | ||
// _, err := e.AddPolicies(pPolicies) | ||
|
||
for(auto _ : state) { | ||
params = {"user" + std::to_string(GetRandom1000() + 1000), "data" + std::to_string((GetRandom1000() + 1000) / 10), "read"}, e.AddPolicy(params); | ||
} | ||
} | ||
|
||
BENCHMARK(BenchmarkAddPolicyMedium); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and so on. Hope you got the pattern |
||
|
||
static void BenchmarkAddPolicyLarge(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 10000 roles, 1000 resources. | ||
for(int i = 0; i < 10000; ++i) | ||
params = { "user" + std::to_string(i), "data" + std::to_string(i/10), "read" }, e.AddPolicy(params); | ||
|
||
for(auto _ : state) { | ||
params = { "user" + std::to_string(GetRandom10000() + 10000), "data" + std::to_string((GetRandom10000() + 10000) / 10), "read" }, e.AddPolicy(params); | ||
} | ||
} | ||
|
||
BENCHMARK(BenchmarkAddPolicyLarge); | ||
BENCHMARK(BenchmarkAddPolicyLoop); | ||
|
||
static void BenchmarkRemovePolicySmall(benchmark::State& state) { | ||
static void BenchmarkRemovePolicyLoop(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 100 roles, 10 resources. | ||
|
@@ -143,30 +86,5 @@ static void BenchmarkRemovePolicySmall(benchmark::State& state) { | |
params = { "user" + std::to_string(GetRandom100()), "data" + std::to_string(GetRandom100() / 10), "read" }, e.RemovePolicy(params); | ||
} | ||
|
||
BENCHMARK(BenchmarkRemovePolicySmall); | ||
|
||
static void BenchmarkRemovePolicyMedium(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 1000 roles, 100 resources. | ||
for(int i = 0; i < 1000; ++i) | ||
params = {"user" + std::to_string(i), "data" + std::to_string(i / 10), "read"}, e.AddPolicy(params); | ||
|
||
for(auto _ : state) | ||
params = { "user" + std::to_string(GetRandom1000()), "data" + std::to_string(GetRandom1000() / 10), "read" }, e.RemovePolicy(params); | ||
} | ||
|
||
BENCHMARK(BenchmarkRemovePolicyMedium); | ||
|
||
static void BenchmarkRemovePolicyLarge(benchmark::State& state) { | ||
casbin::Enforcer e(basic_model_path); | ||
|
||
// 10000 roles, 1000 resources. | ||
for(int i = 0; i < 10000; ++i) | ||
params = { "user" + std::to_string(i), "data" + std::to_string(i / 10), "read" }, e.AddPolicy(params); | ||
|
||
for(auto _ : state) | ||
params = { "user" + std::to_string(GetRandom10000()), "data" + std::to_string(GetRandom1000()), "read" }, e.RemovePolicy(params); | ||
} | ||
BENCHMARK(BenchmarkRemovePolicyLoop); | ||
|
||
BENCHMARK(BenchmarkRemovePolicyLarge); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think commenting this out is better than deleting it right away. If we comment out only this specific line, the benchmark for
BenchmarkCachedRBACModelSmall
won't run. However, the user has the option to run it anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this @noob20000405?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EmperorYP7 Totally agree with you, I'll change it now.