Skip to content

Commit 539a4f8

Browse files
authored
Merge pull request intel#117 from elbeno/add-metabench
✨ Add metabench for easy compile-time profiling
2 parents ecc786e + 7129024 commit 539a4f8

File tree

8 files changed

+85
-0
lines changed

8 files changed

+85
-0
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ jobs:
8484
working-directory: ${{github.workspace}}/test/library
8585
run: cmake -Bbuild
8686

87+
- name: Build lib metabench tests
88+
working-directory: ${{github.workspace}}/test/library
89+
run: cmake --build build -t metabench_tests
90+
8791
- name: Check lib quality
8892
working-directory: ${{github.workspace}}/test/library
8993
run: cmake --build build -t ci-quality

cmake/cpm_recipes.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,18 @@ if(NOT COMMAND boost_sml_recipe)
4747
"SML_BUILD_TESTS OFF")
4848
endmacro()
4949
endif()
50+
51+
if(NOT COMMAND metabench_recipe)
52+
macro(metabench_recipe VERSION)
53+
add_versioned_package(
54+
NAME
55+
metabench
56+
GITHUB_REPOSITORY
57+
"ldionne/metabench"
58+
GIT_TAG
59+
${VERSION}
60+
DOWNLOAD_ONLY
61+
YES)
62+
include("${metabench_SOURCE_DIR}/metabench.cmake")
63+
endmacro()
64+
endif()

cmake/metabench.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
if(COMMAND add_metabench_profile)
2+
return()
3+
endif()
4+
5+
add_custom_target(metabench_tests)
6+
7+
macro(get_metabench)
8+
if(NOT COMMAND metabench_add_chart)
9+
metabench_recipe(3322ce7)
10+
endif()
11+
endmacro()
12+
13+
function(add_mb_profile)
14+
set(singleValueArgs TARGET RANGE)
15+
set(multiValueArgs TEMPLATES INCLUDE_DIRECTORIES LIBRARIES DS_ARGS
16+
CHART_ARGS)
17+
cmake_parse_arguments(MB "" "${singleValueArgs}" "${multiValueArgs}"
18+
${ARGN})
19+
20+
foreach(template ${MB_TEMPLATES})
21+
string(REPLACE "/" "_" dataset ${template})
22+
metabench_add_dataset(${dataset} "${template}" "${MB_RANGE}" NAME
23+
${dataset} ${MB_DS_ARGS})
24+
target_include_directories(${dataset} PRIVATE ${MB_INCLUDE_DIRECTORIES})
25+
target_link_libraries(${dataset} PRIVATE ${MB_LIBRARIES})
26+
list(APPEND datasets ${dataset})
27+
endforeach()
28+
29+
metabench_add_chart(${MB_TARGET} DATASETS ${datasets} ${MB_CHART_ARGS})
30+
add_dependencies(metabench_tests ${MB_TARGET})
31+
endfunction()
32+
33+
macro(add_metabench_profile)
34+
get_metabench()
35+
add_mb_profile(${ARGN})
36+
endmacro()

cmake/quality.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
1313
include(${CMAKE_CURRENT_LIST_DIR}/sanitizers.cmake)
1414
include(${CMAKE_CURRENT_LIST_DIR}/test.cmake)
1515
include(${CMAKE_CURRENT_LIST_DIR}/benchmark.cmake)
16+
include(${CMAKE_CURRENT_LIST_DIR}/metabench.cmake)
1617

1718
include(${CMAKE_CURRENT_LIST_DIR}/warnings.cmake)
1819
include(${CMAKE_CURRENT_LIST_DIR}/profile.cmake)

test/library/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ target_sources(
3232
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
3333
add_docs(docs)
3434
clang_tidy_interface(TARGET test_lib EXCLUDE_FILESETS exclusions)
35+
add_subdirectory(test)
3536
endif()

test/library/test/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_metabench_profile(
2+
TARGET
3+
mb_test
4+
RANGE
5+
"[1, 100, 200]"
6+
TEMPLATES
7+
test_array.cpp.erb
8+
test_tuple.cpp.erb
9+
DS_ARGS
10+
MEDIAN_OF
11+
3
12+
CHART_ARGS
13+
TITLE
14+
"test")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <array>
2+
3+
auto main() -> int {
4+
#if defined(METABENCH)
5+
[[maybe_unused]] auto a = std::array{<%= (1..n).to_a.join(', ') %>};
6+
#endif
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <tuple>
2+
3+
auto main() -> int {
4+
#if defined(METABENCH)
5+
[[maybe_unused]] auto t = std::make_tuple(<%= (1..n).to_a.join(', ') %>);
6+
#endif
7+
}

0 commit comments

Comments
 (0)