Skip to content

Commit

Permalink
feat: Initiated benchmark workflow (#114)
Browse files Browse the repository at this point in the history
* feat: Added benchmarking

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>

* feat: Added build test option

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>

* fix: removed overhead

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>

* feat: added GitHub Actions for benchmark

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>

* fix: Updated to Release config

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>

* fix: updated CopyRight

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>

* fix: Added 2021 copyright

Signed-off-by: Yash Pandey (YP) <yash.btech.cs19@iiitranchi.ac.in>
  • Loading branch information
EmperorYP7 authored Jun 30, 2021
1 parent 0cd1fc5 commit 617ba26
Show file tree
Hide file tree
Showing 24 changed files with 224 additions and 26 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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.

name: Benchmark

on: [push, pull_request]

jobs:
benchmark:
name: Benchmark
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v2
- name: Configuring CMake files
id: building-files
run: |
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE:STRING=Release
- name: Building library
id: building-lib
run: |
cd build && cmake --build . --config Release --target all -j 10 --
- name: Run Benchmark
id: run-benchmark
run: |
cd ./build/tests/benchmarks
./casbin_benchmark
- name: Cleanup
id: clean-up
run: |
rm -r build
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The casbin Authors. All Rights Reserved.
# 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.
Expand All @@ -11,7 +11,6 @@
# 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.
#

name: CI

Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ endif()
###############################################################################
# Global CMake options.

option(CASBIN_BUILD_TEST "State whether to build test" ON)
option(CASBIN_BUILD_BENCHMARK "State whether to build benchmarks" ON)

# Do not output install messages.
if(NOT DEFINED CMAKE_INSTALL_MESSAGE)
set(CMAKE_INSTALL_MESSAGE "NEVER")
endif()

enable_testing()
if(CASBIN_BUILD_TEST)
enable_testing()
endif()

add_subdirectory(tests)

# Change the path max size to avoid problem on Windows.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ https://casbin.org/docs/en/tutorials
Here's the summary:
```cpp
#include <casbin/casbin.h>
#include <string>
void IsAuthorized() {
casbin::Enforcer e("./path/to/model.conf", "./path/to/policy.csv");
Expand Down
2 changes: 1 addition & 1 deletion casbin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The casbin Authors. All Rights Reserved.
# 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.
Expand Down
20 changes: 20 additions & 0 deletions cmake/modules/FindExtPackages.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 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.

###############################################################################
### Global package options ###

Expand All @@ -13,3 +27,9 @@ set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY ON CACHE BOOL
# googletest
# https://github.com/google/googletest
find_package(googletest 1.11.0 REQUIRED)

if(CASBIN_BUILD_BENCHMARK)
# benchmark
# https://github.com/google/benchmark
find_package(benchmark 1.5.5 REQUIRED)
endif()
23 changes: 23 additions & 0 deletions cmake/modules/Findbenchmark.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

include(FetchContent)

FetchContent_Declare(
benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.5.5.zip
)

set(BENCHMARK_ENABLE_TESTING OFF)
FetchContent_MakeAvailable(benchmark)
14 changes: 14 additions & 0 deletions cmake/modules/Findgoogletest.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 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.

include(FetchContent)
FetchContent_Declare(
googletest
Expand Down
26 changes: 16 additions & 10 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The casbin Authors. All Rights Reserved.
# 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.
Expand All @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(CMAKE_CXX_STANDARD 17)
if(CASBIN_BUILD_TEST)
set(CMAKE_CXX_STANDARD 17)

add_executable(
casbintest
Expand All @@ -30,13 +31,18 @@ add_executable(
util_test.cpp
)

target_include_directories(casbintest PUBLIC ${CMAKE_SOURCE_DIR})
target_include_directories(casbintest PUBLIC ${CMAKE_SOURCE_DIR})

target_link_libraries(
casbintest
gtest_main
casbin
)
target_link_libraries(
casbintest
gtest_main
casbin
)

include(GoogleTest)
gtest_discover_tests(casbintest)
endif()

include(GoogleTest)
gtest_discover_tests(casbintest)
if(CASBIN_BUILD_BENCHMARK)
add_subdirectory(benchmarks)
endif()
26 changes: 26 additions & 0 deletions tests/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.

add_executable(casbin_benchmark
main.cpp
enforcer_cached_b.cpp
)

target_include_directories(casbin_benchmark PUBLIC ${CMAKE_SOURCE_DIR})

target_link_libraries(
casbin_benchmark
benchmark
casbin
)
39 changes: 39 additions & 0 deletions tests/benchmarks/enforcer_cached_b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 a test file for benchmarking the performance of casbin::CachedEnforcer
*/

#include <benchmark/benchmark.h>
#include <casbin/casbin.h>

static void BenchmarkCachedBasicModel(benchmark::State& state) {
casbin::CachedEnforcer e("../../../examples/basic_model.conf", "../../../examples/basic_policy.csv");
std::vector<std::string> request = {"alice", "data1", "read"};
for (auto _ : state)
e.Enforce(request);
}

BENCHMARK(BenchmarkCachedBasicModel);


static void BenchmarkCachedRBACModel(benchmark::State& state) {
casbin::CachedEnforcer e("../../../examples/rbac_model.conf", "../../../examples/rbac_policy.csv");
std::vector<std::string> request = {"alice", "data2", "read"};
for (auto _ : state)
e.Enforce(request);
}

BENCHMARK(BenchmarkCachedRBACModel);
21 changes: 21 additions & 0 deletions tests/benchmarks/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 the main file that provides entry point to the entire benchmarking workflow
*/

#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
2 changes: 1 addition & 1 deletion tests/built_in_functions_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/config_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/enforcer_cached_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/enforcer_synced_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/enforcer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/management_api_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/model_enforcer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/model_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/rbac_api_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/rbac_api_with_domains_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/role_manager_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/util_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The casbin Authors. All Rights Reserved.
* 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.
Expand Down

0 comments on commit 617ba26

Please sign in to comment.