Skip to content

Commit 617ba26

Browse files
authored
feat: Initiated benchmark workflow (#114)
* feat: Added benchmarking Signed-off-by: Yash Pandey (YP) <[email protected]> * feat: Added build test option Signed-off-by: Yash Pandey (YP) <[email protected]> * fix: removed overhead Signed-off-by: Yash Pandey (YP) <[email protected]> * feat: added GitHub Actions for benchmark Signed-off-by: Yash Pandey (YP) <[email protected]> * fix: Updated to Release config Signed-off-by: Yash Pandey (YP) <[email protected]> * fix: updated CopyRight Signed-off-by: Yash Pandey (YP) <[email protected]> * fix: Added 2021 copyright Signed-off-by: Yash Pandey (YP) <[email protected]>
1 parent 0cd1fc5 commit 617ba26

24 files changed

+224
-26
lines changed

.github/workflows/benchmark.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Benchmark
16+
17+
on: [push, pull_request]
18+
19+
jobs:
20+
benchmark:
21+
name: Benchmark
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
id: checkout
26+
uses: actions/checkout@v2
27+
- name: Configuring CMake files
28+
id: building-files
29+
run: |
30+
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE:STRING=Release
31+
- name: Building library
32+
id: building-lib
33+
run: |
34+
cd build && cmake --build . --config Release --target all -j 10 --
35+
- name: Run Benchmark
36+
id: run-benchmark
37+
run: |
38+
cd ./build/tests/benchmarks
39+
./casbin_benchmark
40+
- name: Cleanup
41+
id: clean-up
42+
run: |
43+
rm -r build

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 The casbin Authors. All Rights Reserved.
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
22

33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
#
1514

1615
name: CI
1716

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ endif()
4848
###############################################################################
4949
# Global CMake options.
5050

51+
option(CASBIN_BUILD_TEST "State whether to build test" ON)
52+
option(CASBIN_BUILD_BENCHMARK "State whether to build benchmarks" ON)
53+
5154
# Do not output install messages.
5255
if(NOT DEFINED CMAKE_INSTALL_MESSAGE)
5356
set(CMAKE_INSTALL_MESSAGE "NEVER")
5457
endif()
5558

56-
enable_testing()
59+
if(CASBIN_BUILD_TEST)
60+
enable_testing()
61+
endif()
62+
5763
add_subdirectory(tests)
5864

5965
# Change the path max size to avoid problem on Windows.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ https://casbin.org/docs/en/tutorials
192192
Here's the summary:
193193
```cpp
194194
#include <casbin/casbin.h>
195+
#include <string>
195196
196197
void IsAuthorized() {
197198
casbin::Enforcer e("./path/to/model.conf", "./path/to/policy.csv");

casbin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 The casbin Authors. All Rights Reserved.
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

cmake/modules/FindExtPackages.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
###############################################################################
216
### Global package options ###
317

@@ -13,3 +27,9 @@ set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY ON CACHE BOOL
1327
# googletest
1428
# https://github.com/google/googletest
1529
find_package(googletest 1.11.0 REQUIRED)
30+
31+
if(CASBIN_BUILD_BENCHMARK)
32+
# benchmark
33+
# https://github.com/google/benchmark
34+
find_package(benchmark 1.5.5 REQUIRED)
35+
endif()

cmake/modules/Findbenchmark.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
include(FetchContent)
16+
17+
FetchContent_Declare(
18+
benchmark
19+
URL https://github.com/google/benchmark/archive/refs/tags/v1.5.5.zip
20+
)
21+
22+
set(BENCHMARK_ENABLE_TESTING OFF)
23+
FetchContent_MakeAvailable(benchmark)

cmake/modules/Findgoogletest.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
include(FetchContent)
216
FetchContent_Declare(
317
googletest

tests/CMakeLists.txt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 The casbin Authors. All Rights Reserved.
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
set(CMAKE_CXX_STANDARD 17)
15+
if(CASBIN_BUILD_TEST)
16+
set(CMAKE_CXX_STANDARD 17)
1617

1718
add_executable(
1819
casbintest
@@ -30,13 +31,18 @@ add_executable(
3031
util_test.cpp
3132
)
3233

33-
target_include_directories(casbintest PUBLIC ${CMAKE_SOURCE_DIR})
34+
target_include_directories(casbintest PUBLIC ${CMAKE_SOURCE_DIR})
3435

35-
target_link_libraries(
36-
casbintest
37-
gtest_main
38-
casbin
39-
)
36+
target_link_libraries(
37+
casbintest
38+
gtest_main
39+
casbin
40+
)
41+
42+
include(GoogleTest)
43+
gtest_discover_tests(casbintest)
44+
endif()
4045

41-
include(GoogleTest)
42-
gtest_discover_tests(casbintest)
46+
if(CASBIN_BUILD_BENCHMARK)
47+
add_subdirectory(benchmarks)
48+
endif()

tests/benchmarks/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2021 The casbin Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
add_executable(casbin_benchmark
16+
main.cpp
17+
enforcer_cached_b.cpp
18+
)
19+
20+
target_include_directories(casbin_benchmark PUBLIC ${CMAKE_SOURCE_DIR})
21+
22+
target_link_libraries(
23+
casbin_benchmark
24+
benchmark
25+
casbin
26+
)

0 commit comments

Comments
 (0)