1- # Copyright (C) 2023 Intel Corporation
1+ # Copyright (C) 2023-2024 Intel Corporation
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 (FetchContent)
6+ FetchContent_Declare(
7+ googlebenchmark
8+ GIT_REPOSITORY https://github.com/google/benchmark.git
9+ GIT_TAG v1.9.0)
10+
11+ set (BENCHMARK_ENABLE_GTEST_TESTS
12+ OFF
13+ CACHE BOOL "" FORCE)
14+ set (BENCHMARK_ENABLE_TESTING
15+ OFF
16+ CACHE BOOL "" FORCE)
17+ set (BENCHMARK_ENABLE_INSTALL
18+ OFF
19+ CACHE BOOL "" FORCE)
20+ FetchContent_MakeAvailable(googlebenchmark)
21+
522# In MSVC builds, there is no way to determine the actual build type during the
623# CMake configuration step. Therefore, this message is printed in all MSVC
724# builds.
@@ -32,7 +49,7 @@ function(add_umf_benchmark)
3249 "${multiValueArgs} "
3350 ${ARGN} )
3451
35- set (BENCH_NAME umf-bench- ${ARG_NAME} )
52+ set (BENCH_NAME umf-${ARG_NAME} )
3653
3754 set (BENCH_LIBS ${ARG_LIBS} umf)
3855
@@ -52,13 +69,17 @@ function(add_umf_benchmark)
5269 COMMAND ${BENCH_NAME}
5370 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} )
5471
55- # Benchmark passes if it prints "PASSED" in the output, because ubench of
56- # scalable pool fails if the confidence interval exceeds maximum permitted
57- # 2.5%.
58- set_tests_properties (
59- ${BENCH_NAME} PROPERTIES
60- LABELS "benchmark"
61- PASS_REGULAR_EXPRESSION "PASSED" )
72+ if ("${BENCH_NAME} " STREQUAL "umf-ubench" )
73+ # Benchmark passes if it prints "PASSED" in the output, because ubench
74+ # of scalable pool fails if the confidence interval exceeds maximum
75+ # permitted 2.5%.
76+ set_tests_properties (
77+ ${BENCH_NAME} PROPERTIES
78+ LABELS "benchmark"
79+ PASS_REGULAR_EXPRESSION "PASSED" )
80+ else ()
81+ set_tests_properties (${BENCH_NAME} PROPERTIES LABELS "benchmark" )
82+ endif ()
6283
6384 if (WINDOWS)
6485 # append PATH to DLLs
@@ -68,19 +89,19 @@ function(add_umf_benchmark)
6889
6990 if (UMF_BUILD_LIBUMF_POOL_DISJOINT)
7091 target_compile_definitions (${BENCH_NAME}
71- PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT =1)
92+ PRIVATE UMF_POOL_DISJOINT_ENABLED =1)
7293 endif ()
73- if (UMF_BUILD_LIBUMF_POOL_JEMALLOC )
94+ if (UMF_POOL_JEMALLOC_ENABLED )
7495 target_compile_definitions (${BENCH_NAME}
75- PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC =1)
96+ PRIVATE UMF_POOL_JEMALLOC_ENABLED =1)
7697 endif ()
7798 if (UMF_POOL_SCALABLE_ENABLED)
7899 target_compile_definitions (${BENCH_NAME}
79100 PRIVATE UMF_POOL_SCALABLE_ENABLED=1)
80101 endif ()
81102 if (UMF_BUILD_LEVEL_ZERO_PROVIDER)
82103 target_compile_definitions (${BENCH_NAME}
83- PRIVATE UMF_BUILD_LEVEL_ZERO_PROVIDER =1)
104+ PRIVATE UMF_PROVIDER_LEVEL_ZERO_ENABLED =1)
84105 target_include_directories (
85106 ${BENCH_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR} /test /common
86107 ${LEVEL_ZERO_INCLUDE_DIRS} )
@@ -121,6 +142,12 @@ add_umf_benchmark(
121142 LIBS ${LIBS_OPTIONAL}
122143 LIBDIRS ${LIB_DIRS} )
123144
145+ add_umf_benchmark(
146+ NAME benchmark
147+ SRCS benchmark.cpp
148+ LIBS ${LIBS_OPTIONAL} benchmark::benchmark
149+ LIBDIRS ${LIB_DIRS} )
150+
124151if (UMF_BUILD_BENCHMARKS_MT)
125152 add_umf_benchmark(
126153 NAME multithreaded
0 commit comments