Skip to content

Commit a2b6b11

Browse files
committed
Add add_umf_benchmark() to remove duplicated code in benchmarks CMakeLists
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent d502646 commit a2b6b11

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

benchmark/CMakeLists.txt

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,84 @@
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
include(FindThreads)
6-
75
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
86
message(WARNING "The benchmarks SHOULD NOT be run in the Debug build type!")
97
endif()
108

11-
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
12-
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool)
13-
endif()
14-
15-
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
16-
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool)
17-
endif()
18-
19-
if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
20-
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} scalable_pool)
9+
if (UMF_BUILD_BENCHMARKS_MT)
10+
include(FindThreads)
2111
endif()
2212

23-
add_executable(ubench ubench.c)
13+
function(add_umf_benchmark)
14+
# NAME - a name of the benchmark
15+
# SRCS - source files
16+
# LIBS - libraries to be linked with
17+
set(oneValueArgs NAME)
18+
set(multiValueArgs SRCS LIBS)
19+
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
2420

25-
if(LINUX)
26-
set(LIBS_LINUX m)
27-
endif()
21+
set(BENCH_NAME umf-bench-${ARG_NAME})
2822

29-
add_dependencies(ubench
30-
umf
31-
${LIBS_OPTIONAL})
23+
set(BENCH_LIBS umf ${ARG_LIBS})
3224

33-
target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/ ${UMF_CMAKE_SOURCE_DIR}/src/utils/)
25+
add_umf_executable(NAME ${BENCH_NAME} SRCS ${ARG_SRCS} LIBS ${BENCH_LIBS})
3426

35-
target_link_libraries(ubench
36-
umf
37-
${LIBS_OPTIONAL}
38-
${CMAKE_THREAD_LIBS_INIT}
39-
${LIBS_LINUX})
27+
target_include_directories(${BENCH_NAME} PRIVATE
28+
${UMF_CMAKE_SOURCE_DIR}/include
29+
${UMF_CMAKE_SOURCE_DIR}/src/utils)
4030

41-
if (UMF_BUILD_BENCHMARKS_MT)
42-
add_executable(multithread_bench multithread.cpp)
43-
target_link_libraries(multithread_bench
44-
umf
45-
${LIBS_OPTIONAL}
46-
pthread
47-
${LIBS_LINUX})
48-
target_include_directories(multithread_bench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
49-
endif()
31+
add_test(NAME ${BENCH_NAME}
32+
COMMAND ${BENCH_NAME}
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
5034

51-
if (UMF_BUILD_OS_MEMORY_PROVIDER)
52-
target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
35+
# Benchmark passes if it prints "PASSED" in the output,
36+
# because ubench of scalable pool fails if the confidence interval
37+
# exceeds maximum permitted 2.5%.
38+
set_tests_properties(${BENCH_NAME} PROPERTIES
39+
LABELS "benchmark"
40+
PASS_REGULAR_EXPRESSION "PASSED")
5341

54-
if (UMF_BUILD_BENCHMARKS_MT)
55-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
42+
if(WINDOWS)
43+
# append PATH to DLLs
44+
set(DLL_PATH_LIST "PATH=path_list_append:../bin/$<CONFIG>")
45+
if(LIBHWLOC_DLL_DIRS)
46+
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_DLL_DIRS}")
5647
endif()
48+
set_property(TEST ${BENCH_NAME} PROPERTY ENVIRONMENT_MODIFICATION "${DLL_PATH_LIST}")
49+
endif()
50+
51+
if (UMF_BUILD_OS_MEMORY_PROVIDER)
52+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
53+
endif()
54+
if (UMF_BUILD_LIBUMF_POOL_DISJOINT)
55+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)
56+
endif()
57+
if (UMF_BUILD_LIBUMF_POOL_JEMALLOC)
58+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1)
59+
endif()
60+
if (UMF_BUILD_LIBUMF_POOL_SCALABLE)
61+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1)
62+
endif()
63+
endfunction()
64+
65+
# optional libraries
66+
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
67+
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool)
5768
endif()
58-
59-
if (UMF_BUILD_OS_MEMORY_PROVIDER)
60-
target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
69+
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
70+
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool)
6171
endif()
62-
63-
if (UMF_BUILD_LIBUMF_POOL_DISJOINT)
64-
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)
65-
66-
if (UMF_BUILD_BENCHMARKS_MT)
67-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)
68-
endif()
72+
if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
73+
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} scalable_pool)
6974
endif()
70-
71-
if (UMF_BUILD_LIBUMF_POOL_JEMALLOC)
72-
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1)
73-
74-
if (UMF_BUILD_BENCHMARKS_MT)
75-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1)
76-
endif()
75+
if(LINUX)
76+
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} m)
7777
endif()
7878

79-
if (UMF_BUILD_LIBUMF_POOL_SCALABLE)
80-
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1)
79+
# BENCHMARKS
8180

82-
if (UMF_BUILD_BENCHMARKS_MT)
83-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1)
84-
endif()
81+
add_umf_benchmark(NAME ubench SRCS ubench.c LIBS ${LIBS_OPTIONAL})
82+
83+
if (UMF_BUILD_BENCHMARKS_MT)
84+
add_umf_benchmark(NAME multithreaded SRCS multithread.cpp LIBS ${LIBS_OPTIONAL} ${CMAKE_THREAD_LIBS_INIT})
8585
endif()

0 commit comments

Comments
 (0)