From f244357c95172f5f7a6a5ba111476a2abd11b16f Mon Sep 17 00:00:00 2001 From: Zelourses <24527982+Zelourses@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:27:00 +0300 Subject: [PATCH] Additional instructions for Windows + changed CMakeLists.txt Added: - Windows build instructions to `readme.md` Changed: - now `CMakeLists.txt` for every benchmark will generate right test for Windows. --- coro-fibs/CMakeLists.txt | 20 ++++++++++++----- excret/CMakeLists.txt | 36 ++++++++++++++++++++++++------- inline/CMakeLists.txt | 17 +++++++++++---- noexcept-qsort/CMakeLists.txt | 36 ++++++++++++++++++++++++------- ranges-filter/CMakeLists.txt | 18 ++++++++++++---- ranges-projector/CMakeLists.txt | 18 ++++++++++++---- readme.md | 19 +++++++++++++++-- virtual-inherit/CMakeLists.txt | 18 ++++++++++++---- virtual-inline/CMakeLists.txt | 18 ++++++++++++---- virtual-inline/virtinl.cc | 10 +++++++-- virtual-overhead/CMakeLists.txt | 38 ++++++++++++++++++++++++++------- 11 files changed, 195 insertions(+), 53 deletions(-) diff --git a/coro-fibs/CMakeLists.txt b/coro-fibs/CMakeLists.txt index 1750f63..c800300 100644 --- a/coro-fibs/CMakeLists.txt +++ b/coro-fibs/CMakeLists.txt @@ -4,9 +4,19 @@ add_executable(${TNAME} corofibs.cc sumfib_module.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) +# cannot use cmd here because of some strange things in path: https://gitlab.kitware.com/cmake/cmake/-/issues/17067 + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() +set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) diff --git a/excret/CMakeLists.txt b/excret/CMakeLists.txt index 8e95329..ddd0a85 100644 --- a/excret/CMakeLists.txt +++ b/excret/CMakeLists.txt @@ -6,12 +6,22 @@ add_executable(${TNAME} exc_ret_1.cc exc_ret_2.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) + # same benchmark, version when no exception happened SET(TNAME exc_ret_noexc) @@ -21,8 +31,18 @@ target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) target_compile_definitions(${TNAME} PUBLIC NOEXC) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) + diff --git a/inline/CMakeLists.txt b/inline/CMakeLists.txt index 232f579..09b5581 100644 --- a/inline/CMakeLists.txt +++ b/inline/CMakeLists.txt @@ -4,9 +4,18 @@ add_executable(${TNAME} extswap.cc partition.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) diff --git a/noexcept-qsort/CMakeLists.txt b/noexcept-qsort/CMakeLists.txt index e4fffd5..ec530e5 100644 --- a/noexcept-qsort/CMakeLists.txt +++ b/noexcept-qsort/CMakeLists.txt @@ -4,22 +4,42 @@ add_executable(${TNAME} exc_qsort.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) + SET(TNAME exc_partition) add_executable(${TNAME} exc_partition.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) + diff --git a/ranges-filter/CMakeLists.txt b/ranges-filter/CMakeLists.txt index 6af0ec8..cccb66d 100644 --- a/ranges-filter/CMakeLists.txt +++ b/ranges-filter/CMakeLists.txt @@ -4,10 +4,20 @@ add_executable(${TNAME} filter.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) + diff --git a/ranges-projector/CMakeLists.txt b/ranges-projector/CMakeLists.txt index 143bc9b..2807590 100644 --- a/ranges-projector/CMakeLists.txt +++ b/ranges-projector/CMakeLists.txt @@ -4,10 +4,20 @@ add_executable(${TNAME} projector.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) + diff --git a/readme.md b/readme.md index b1b5072..480046c 100644 --- a/readme.md +++ b/readme.md @@ -31,14 +31,29 @@ If you have custom compiler be sure it is inside profile. Now you are ready for main build and run. Conan will download all dependencies for you. -``` +## Linux build + +```bash conan install conanfile.txt --build=missing cmake -S . -B build/Release --toolchain build/Release/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release cmake --build build/Release env CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/Release --target test --parallel 1 ``` -This will take some time, be patient. Benchmarking results will be created in the build/Release/CSVS folder. +## Windows build + +It is highly recommended to use developer powershell + +```pwsh +conan install conanfile.txt --build=missing +cmake -S . -B .\build --toolchain .\build\generators\conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_DEFAULT_CMP0091=NEW +cmake --build --preset conan-release +powershell -command { $env:CTEST_OUTPUT_ON_FAILURE='1'; cmake --build --preset conan-release --target RUN_TESTS --parallel 1 } +``` + +--- + +This will take some time, be patient. Benchmarking results will be created in the build/Release/CSVS folder for Linux and in build/CSVS folder for Windows. You are welcome to create MR in results folder with your architecture and name it will help my talk! diff --git a/virtual-inherit/CMakeLists.txt b/virtual-inherit/CMakeLists.txt index 4e5af4f..3cc1a7a 100644 --- a/virtual-inherit/CMakeLists.txt +++ b/virtual-inherit/CMakeLists.txt @@ -4,10 +4,20 @@ add_executable(${TNAME} virtinh.cc fmodule.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() + set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) diff --git a/virtual-inline/CMakeLists.txt b/virtual-inline/CMakeLists.txt index 3a430e8..aed5db1 100644 --- a/virtual-inline/CMakeLists.txt +++ b/virtual-inline/CMakeLists.txt @@ -4,10 +4,20 @@ add_executable(${TNAME} virtinl.cc fmodule.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() + set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) diff --git a/virtual-inline/virtinl.cc b/virtual-inline/virtinl.cc index f4d7a6d..bfbab4f 100644 --- a/virtual-inline/virtinl.cc +++ b/virtual-inline/virtinl.cc @@ -14,6 +14,12 @@ #include "benchmark/cppbenchmark.h" #endif +#if defined(_WIN32) || defined(_WIN64) +#define NOINLINE __declspec(noinline) +#else +#define NOINLINE __attribute__((noinline)) +#endif + constexpr int NCALL = 100; constexpr int NBMK = 10000; @@ -49,14 +55,14 @@ struct VirtDerived : VirtBase { } }; -int __attribute__((noinline)) startup(NonVirt *nv) { +NOINLINE int startup(NonVirt *nv) { int sum = 0; for (int i = 0; i < NBMK; ++i) sum += nv->bar(NCALL); return sum; } -int __attribute__((noinline)) startup(VirtBase *vb) { +NOINLINE int startup(VirtBase *vb) { int sum = 0; for (int i = 0; i < NBMK; ++i) sum += vb->bar(NCALL); diff --git a/virtual-overhead/CMakeLists.txt b/virtual-overhead/CMakeLists.txt index 2edb649..bfdc647 100644 --- a/virtual-overhead/CMakeLists.txt +++ b/virtual-overhead/CMakeLists.txt @@ -4,22 +4,44 @@ add_executable(${TNAME} virtual-1.cc virtual-2.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() + set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) + SET(TNAME virtual-shuffle) add_executable(${TNAME} virtual-shuffle-1.cc virtual-shuffle-2.cc) target_compile_features(${TNAME} PRIVATE cxx_std_20) target_link_libraries(${TNAME} cppbenchmark::cppbenchmark) -add_test( - NAME TEST_${TNAME} - COMMAND sh -c "./${TNAME} -q -o csv > ${CSVS}/${TNAME}.csv" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +file(TO_NATIVE_PATH "${CSVS}/${TNAME}.csv" CSV_OUT) + +if (WIN32) + add_test( + NAME TEST_${TNAME} + COMMAND powershell -command "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +else() + add_test( + NAME TEST_${TNAME} + COMMAND sh -c "$ -q -o csv > ${CSV_OUT}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() + set_tests_properties(${TEST_TARGET} PROPERTIES DEPENDS ${TNAME}) +