Skip to content

Commit 7cb201d

Browse files
authored
🎉 Add benchmarks (#77)
* 🎉 Adding benchmarks * LTO is too powerful it eliminates everything * no-inline is working now * Add untested no-lto platforms * Working benchmarks * Add start() and stop() to test_package * Remove generated tests I plan to merge the depths into single test file. I don't think we learn anything useful from running the test in separate files. * cleanup and revert files * add license
1 parent 4af7226 commit 7cb201d

16 files changed

Lines changed: 1641 additions & 1742 deletions

File tree

benchmark/.clangd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CompileFlags:
2+
CompilationDatabase: .
3+
BuiltinHeaders: QueryDriver

benchmark/CMakeLists.txt

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright 2024 - 2025 Khalil Estell and the libhal contributors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cmake_minimum_required(VERSION 3.25)
16+
17+
project(benchmark-error-handling LANGUAGES CXX)
18+
19+
# Always check that the $ENV{LIBHAL_PLATFORM_LIBRARY} & $ENV{LIBHAL_PLATFORM}
20+
# environment variables are set by the profile.
21+
if("$ENV{LIBHAL_PLATFORM_LIBRARY}" STREQUAL "")
22+
message(FATAL_ERROR
23+
"Build environment variable LIBHAL_PLATFORM_LIBRARY is required for " "this project.")
24+
endif()
25+
if("$ENV{LIBHAL_PLATFORM}" STREQUAL "")
26+
message(FATAL_ERROR
27+
"Build environment variable LIBHAL_PLATFORM is required for "
28+
"this project.")
29+
endif()
30+
31+
find_package(libhal-$ENV{LIBHAL_PLATFORM_LIBRARY} REQUIRED)
32+
find_package(prebuilt-picolibc QUIET)
33+
34+
if(${CMAKE_CROSSCOMPILING})
35+
find_package(${PACKAGE} REQUIRED)
36+
endif()
37+
38+
set(startup_source_files main.cpp filler.cpp)
39+
40+
# Makes the platform/<platform_name>.cpp file optional
41+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/platforms/$ENV{LIBHAL_PLATFORM}.cpp")
42+
list(APPEND startup_source_files platforms/$ENV{LIBHAL_PLATFORM}.cpp)
43+
endif()
44+
45+
add_library(startup_code ${startup_source_files})
46+
47+
target_include_directories(startup_code PUBLIC .)
48+
target_compile_options(startup_code PRIVATE
49+
-g
50+
-Werror
51+
-Wall
52+
-Wextra
53+
-Wshadow
54+
-fno-threadsafe-statics
55+
$<$<COMPILE_LANGUAGE:CXX>:-fexceptions -fno-rtti>
56+
)
57+
58+
target_link_libraries(startup_code PRIVATE
59+
libhal::$ENV{LIBHAL_PLATFORM_LIBRARY}
60+
)
61+
62+
if(prebuilt-picolibc_FOUND)
63+
target_link_libraries(startup_code PRIVATE picolibc)
64+
message(STATUS "Found picolibc, linking it in!")
65+
endif()
66+
67+
# Glob all the files in the directory 'generated_tests'
68+
file(GLOB GENERATED_TEST "${CMAKE_CURRENT_SOURCE_DIR}/generated_tests/*.cpp")
69+
70+
foreach(test_path ${GENERATED_TEST})
71+
get_filename_component(test_file_name ${test_path} NAME)
72+
set(elf ${test_file_name}.elf)
73+
message(STATUS "Generating Demo for \"${elf}\"")
74+
add_executable(${elf} ${test_path})
75+
76+
target_compile_options(${elf} PRIVATE
77+
-g
78+
-Werror
79+
-Wall
80+
-Wextra
81+
-Wshadow
82+
-fno-threadsafe-statics
83+
$<$<COMPILE_LANGUAGE:CXX>:-fexceptions -fno-rtti>
84+
)
85+
86+
target_link_libraries(${elf} PRIVATE
87+
startup_code
88+
libhal::$ENV{LIBHAL_PLATFORM_LIBRARY}
89+
)
90+
91+
target_link_options(${elf} PRIVATE -fno-threadsafe-statics)
92+
93+
if(prebuilt-picolibc_FOUND)
94+
target_link_libraries(${elf} PRIVATE picolibc)
95+
endif()
96+
97+
if(${CMAKE_CROSSCOMPILING})
98+
# Convert elf into .bin, .hex and other formats needed for programming
99+
# devices.
100+
libhal_post_build(${elf})
101+
libhal_disassemble(${elf})
102+
endif()
103+
endforeach()

benchmark/conanfile.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2024 - 2025 Khalil Estell and the libhal contributors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from conan import ConanFile
16+
17+
18+
class demos(ConanFile):
19+
python_requires = "libhal-bootstrap/[>=4.3.0 <5]"
20+
python_requires_extend = "libhal-bootstrap.demo"
21+
22+
def requirements(self):
23+
bootstrap = self.python_requires["libhal-bootstrap"]
24+
bootstrap.module.add_demo_requirements(self)
25+
if self.options.platform != "mac":
26+
self.requires("libhal-exceptions/[1.2.0 || latest]")

benchmark/filler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file filler.cpp
3+
*
4+
* This file includes filler functions which are added to both result and
5+
* exceptions. The hypothesis and expectation is that the additional functions
6+
* will have no effect on the result experiment and will have an effect on the
7+
* exceptions experiment. Exceptions are effected because exceptions perform a
8+
* binary search through the exception index to find the handling info for each
9+
* function.
10+
*
11+
*/
12+
13+
/**
14+
* @brief Performs some set of actions that forces the compiler to link in all
15+
* of the filler functions.
16+
*/
17+
void activate_filler();

0 commit comments

Comments
 (0)