-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add a benchmark tests option (#162)
* fix: expedite benchmark tests Signed-off-by: noob20000405 <vincent4869code@gmail.com> * fix: add a benchmark tests option Signed-off-by: noob20000405 <vincent4869code@gmail.com> * fix: add a benchmark tests option Signed-off-by: noob20000405 <vincent4869code@gmail.com> * fix: modification of intensive benchmark option Signed-off-by: noob20000405 <vincent4869code@gmail.com> * fix: modification of intensive benchmark option Signed-off-by: noob20000405 <vincent4869code@gmail.com>
- Loading branch information
1 parent
abaa217
commit 7790669
Showing
10 changed files
with
361 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2021 The casbin Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* This is an intensive test file for benchmarking the performance of casbin::CachedEnforcer | ||
*/ | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <casbin/casbin.h> | ||
#include "config_path.h" | ||
|
||
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); | ||
|
||
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); | ||
|
||
static void BenchmarkCachedRBACModelMediumParallel(benchmark::State& state) { | ||
|
||
casbin::CachedEnforcer e(rbac_model_path, "", false); | ||
casbin::DataList params = {"user5001", "data150", "read"}; | ||
if (state.thread_index == 0) | ||
{ | ||
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); | ||
|
||
std::vector<std::vector<std::string>> g_policies(100000); | ||
for (int i = 0; i < 100000; ++i) | ||
e.AddGroupingPolicy({ "user" + std::to_string(i), "group" + std::to_string(i/10) }); | ||
} | ||
for (auto _ : state) { | ||
e.Enforce(params); | ||
} | ||
} | ||
// BENCHMARK(BenchmarkCachedRBACModelMediumParallel)->Threads(10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.