Skip to content

Commit 5551cbe

Browse files
committed
add generic benchmarking utility, and clean up other benchmarks. Update readme and cmake (allow make bench).
1 parent 4d4f3d0 commit 5551cbe

File tree

9 files changed

+251
-350
lines changed

9 files changed

+251
-350
lines changed

cpp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ install(FILES include/jsonlogic/details/ast-full.hpp DESTINATION "include/jsonlo
5959
if(JSONLOGIC_ENABLE_BENCH)
6060
message(STATUS "Building benchmarks: ${JSONLOGIC_ENABLE_BENCH}")
6161
add_subdirectory(bench)
62+
add_custom_target(bench
63+
DEPENDS jl-bench-eq jl-bench-membership jl-bench-generic
64+
)
6265
endif()
6366
if(JSONLOGIC_ENABLE_TESTS)
6467
message(STATUS "Building tests: ${JSONLOGIC_ENABLE_TESTS}")

cpp/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ The library is designed to follow the type conversion rules of the reference Jso
88
## Compile and Install
99

1010
The library can be installed using cmake. From the top-level directory,
11-
cmake --preset=default
12-
cd build/release
13-
make
11+
```
12+
cmake --preset=default
13+
cd build/release
14+
make
15+
```
16+
Benchmarks can be made with
17+
```
18+
make bench
19+
```
20+
21+
Tests can be run with
22+
```
23+
make testeval && make test
24+
```
1425

1526
## Use
1627

cpp/bench/CMakeLists.txt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# project(jl-bench-eqs)
44

55
# set(CMAKE_BUILD_TYPE Debug)
6+
include(FetchContent)
7+
68
set(BUILD_TESTING OFF) # Disable Faker tests
79
FetchContent_Declare(faker
810
GIT_REPOSITORY https://github.com/cieslarmichal/faker-cxx.git
@@ -11,6 +13,13 @@ FetchContent_Declare(faker
1113

1214
FetchContent_MakeAvailable(faker)
1315

16+
FetchContent_Declare(
17+
cxxopts
18+
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
19+
GIT_TAG v3.3.1
20+
)
21+
FetchContent_MakeAvailable(cxxopts)
22+
1423
add_executable(jl-bench-eq src/benchmark-equality.cpp)
1524
add_compile_options(-Wall -Wextra -Wunused-variable)
1625

@@ -64,22 +73,20 @@ target_link_libraries(jl-bench-membership PRIVATE jsonlogic faker-cxx)
6473
# ${CMAKE_BINARY_DIR}/_deps/faker-src/include
6574
# )
6675

67-
add_executable(jl-bench-complex1 src/benchmark-complex1.cpp)
68-
target_compile_options(jl-bench-complex1 PRIVATE -O3)
69-
target_include_directories(jl-bench-complex1 SYSTEM PRIVATE
70-
${CMAKE_CURRENT_SOURCE_DIR}/../bench/include
71-
${CMAKE_CURRENT_SOURCE_DIR}/../include
72-
)
73-
74-
configure_file(${CMAKE_SOURCE_DIR}/bench/src/complex1.json ${CMAKE_BINARY_DIR}/bench/complex1.json COPYONLY)
75-
target_link_libraries(jl-bench-complex1 PRIVATE jsonlogic faker-cxx)
7676

77-
add_executable(jl-bench-simple-and src/benchmark-simple-and.cpp)
78-
target_compile_options(jl-bench-simple-and PRIVATE -O3)
79-
target_include_directories(jl-bench-simple-and SYSTEM PRIVATE
77+
add_executable(jl-bench-generic src/benchmark-generic.cpp)
78+
target_include_directories(jl-bench-generic SYSTEM PRIVATE
8079
${CMAKE_CURRENT_SOURCE_DIR}/../bench/include
8180
${CMAKE_CURRENT_SOURCE_DIR}/../include
8281
)
8382

84-
configure_file(${CMAKE_SOURCE_DIR}/bench/src/simple-and.json ${CMAKE_BINARY_DIR}/bench/simple-and.json COPYONLY)
85-
target_link_libraries(jl-bench-simple-and PRIVATE jsonlogic faker-cxx)
83+
target_link_libraries(jl-bench-generic PRIVATE faker-cxx jsonlogic cxxopts)
84+
target_compile_features(jl-bench-generic PRIVATE cxx_std_20)
85+
target_compile_options(jl-bench-generic PRIVATE -O3)
86+
87+
# Copy all .json files from bench/src to the build directory's bench folder
88+
file(GLOB BENCH_JSON_FILES "${CMAKE_SOURCE_DIR}/bench/src/*.json")
89+
foreach(jsonfile ${BENCH_JSON_FILES})
90+
get_filename_component(jsonfile_name "${jsonfile}" NAME)
91+
configure_file(${jsonfile} ${CMAKE_BINARY_DIR}/bench/${jsonfile_name} COPYONLY)
92+
endforeach()

cpp/bench/src/benchmark-complex1.cpp

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)