Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sys/include/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,27 @@ extern "C" {
* @param[in] func function call to benchmark
*/
#define BENCHMARK_FUNC(name, runs, func) \
BENCHMARK_FUNC_WARMUP(name, 0, runs, func)

/**
* @brief Measure the runtime of a given function call
*
* Same as @ref BENCHMARK_FUNC, but do a few warmup iterations before starting
* the benchmark to warm up the dynamic branch predictor state and caches.
*
* @param[in] name name for labeling the output
* @param[in] warmup number of times to run @p func before the benchmark
* @param[in] runs number of times to run @p func during the benchmark
* @param[in] func function call to benchmark
*/
#define BENCHMARK_FUNC_WARMUP(name, warmup, runs, func) \
do { \
ztimer_stopwatch_t timer = { .clock = ZTIMER_USEC }; \
/* warm up cache, branch predictor, ... */ \
unsigned long _warmup = warmup; \
while (_warmup--) { \
func; \
} \
ztimer_stopwatch_start(&timer); \
for (unsigned long i = 0; i < runs; i++) { \
func; \
Expand Down