Skip to content

Commit

Permalink
[bm] Initial benchmark setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 23, 2024
1 parent f33fd04 commit 2437749
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 0 deletions.
110 changes: 110 additions & 0 deletions cmake/dart_defs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,113 @@ function(dart_coverage)
install(DIRECTORY ${gcovr_html_dir}/ DESTINATION ${_ARG_INSTALL_DIR})
endif()
endfunction()

function(dart_benchmarks)
set(prefix _ARG)
set(options)
set(oneValueArgs
TYPE
TARGET_PREFIX
TEST_LIST
)
set(multiValueArgs
SOURCES
INCLUDE_DIRS
LINK_LIBRARIES
LINK_DART_LIBRARIES
COMPILE_DEFINITIONS
)
cmake_parse_arguments(
"${prefix}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
)

if(NOT _ARG_TYPE)
message(
FATAL_ERROR "DEVELOPER ERROR: You must specify a TYPE for your benchmarks!"
)
endif()

if(NOT DEFINED _ARG_SOURCES)
message(STATUS "No benchmarks have been specified for ${_ARG_TYPE}")
else()
list(LENGTH _ARG_SOURCES num_benchmarks)
message(STATUS "Adding ${num_benchmarks} ${_ARG_TYPE} benchmarks")
endif()

if(_ARG_TEST_LIST)
set(${_ARG_TEST_LIST} "")
endif()

foreach(source ${_ARG_SOURCES})

# Set target name: <TYPE>[_<TARGET_PREFIX>]_<source>
set(target_name ${_ARG_TYPE})
if(_ARG_TARGET_PREFIX)
set(target_name "${target_name}_${_ARG_TARGET_PREFIX}")
endif()
get_filename_component(source_name ${source} NAME_WE)
string(REPLACE "bm_" "" source_name ${source_name})
get_filename_component(source_dir ${source} DIRECTORY)
if(source_dir)
string(REPLACE "/" "_" source_prefix ${source_dir})
set(target_name "${target_name}_${source_prefix}_${source_name}")
else()
set(target_name "${target_name}_${source_name}")
endif()

add_executable(${target_name} ${source})
target_include_directories(
${target_name} PRIVATE ${_ARG_INCLUDE_DIRS}
)

target_link_libraries(${target_name} PRIVATE benchmark benchmark_main)

if(UNIX)
# gbenchmark requies pthread when compiled on a Unix machine
target_link_libraries(${target_name} PRIVATE pthread)
endif()

target_link_libraries(
${target_name} PRIVATE ${_ARG_LINK_LIBRARIES}
)

target_compile_definitions(
${target_name} PRIVATE ${_ARG_COMPILE_DEFINITIONS}
)

foreach(dart_lib ${_ARG_LINK_DART_LIBRARIES})
if(NOT TARGET ${dart_lib})
message(FATAL_ERROR "Invalid target: ${dart_lib}")
endif()
target_link_libraries(${target_name} PRIVATE ${dart_lib})
endforeach()

set_target_properties(${target_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${DART_BINARY_DIR}/bin"
)

if(_ARG_TEST_LIST)
list(APPEND ${_ARG_TEST_LIST} ${target_name})
endif()

# Add executable target
add_custom_target(
RUN_${target_name}
COMMAND ${target_name}
COMMENT "Running benchmark ${target_name}..."
VERBATIM
)

dart_property_add(DART_${_ARG_TYPE}_BENCHMARKS ${target_name})
endforeach()

if(_ARG_TEST_LIST)
set(${_ARG_TEST_LIST} "${${_ARG_TEST_LIST}}"
PARENT_SCOPE
)
endif()

dart_format_add(${_ARG_SOURCES})

endfunction()
1 change: 1 addition & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ install-local = { cmd = "cmake --install build --prefix $CONDA_PREFIX", depends_
] }
example-atlas-puppet = { cmd = "cmake --build build --target atlas_puppet --parallel && ./build/bin/atlas_puppet", depends_on = ["configure"] }
example-atlas-simbicon = { cmd = "cmake --build build --target atlas_simbicon --parallel && ./build/bin/atlas_simbicon", depends_on = ["configure"] }
bm-empty = { cmd = "cmake --build build --target BM_INTEGRATION_empty --parallel && ./build/bin/BM_INTEGRATION_empty", depends_on = ["configure"] }

[dependencies]
assimp = ">=5.3.1,<5.4"
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,5 @@ else()
endif()

dart_format_add(GTestUtils.hpp)

add_subdirectory(benchmark)
41 changes: 41 additions & 0 deletions tests/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/master/LICENSE
#
# This file is provided under the following "BSD-style" License:
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

include(FetchContent)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.3
)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(benchmark)

add_subdirectory(unit)
add_subdirectory(integration)
34 changes: 34 additions & 0 deletions tests/benchmark/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/master/LICENSE
#
# This file is provided under the following "BSD-style" License:
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

dart_benchmarks(
TYPE BM_INTEGRATION
SOURCES bm_empty.cpp
)
42 changes: 42 additions & 0 deletions tests/benchmark/integration/bm_empty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2011-2024, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/main/LICENSE
*
* This file is provided under the following "BSD-style" License:
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <benchmark/benchmark.h>

static void BM_Empty(benchmark::State& state)
{
for (auto _ : state) {
// Empty
}
}

BENCHMARK(BM_Empty);
29 changes: 29 additions & 0 deletions tests/benchmark/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/master/LICENSE
#
# This file is provided under the following "BSD-style" License:
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

0 comments on commit 2437749

Please sign in to comment.