All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Benchmark

Framework for running simple runtime benchmarks More...

Detailed Description

Framework for running simple runtime benchmarks

Files

file  benchmark.h
 Interface for running simple benchmarks.
 

Macros

#define BENCHMARK_FUNC(name, runs, func)
 Measure the runtime of a given function call.
 

Functions

void benchmark_print_time (uint32_t time, unsigned long runs, const char *name)
 Output the given time as well as the time per run on STDIO.
 

Macro Definition Documentation

◆ BENCHMARK_FUNC

#define BENCHMARK_FUNC ( name,
runs,
func )
Value:
do { \
ztimer_stopwatch_t timer = { .clock = ZTIMER_USEC }; \
ztimer_stopwatch_start(&timer); \
for (unsigned long i = 0; i < runs; i++) { \
func; \
} \
benchmark_print_time(ztimer_stopwatch_measure(&timer), runs, name); \
ztimer_stopwatch_stop(&timer); \
} while (0)
static uint32_t ztimer_stopwatch_measure(ztimer_stopwatch_t *timer)
Take a measurement from the stop watch timer.
Definition stopwatch.h:64
ztimer_clock_t *const ZTIMER_USEC
Default ztimer microsecond clock.
ztimer stop watch struct
Definition stopwatch.h:29

Measure the runtime of a given function call.

As we are doing a time sensitive measurement here, there is no way around using a preprocessor function, as going with a function pointer or similar would influence the measured runtime...

Parameters
[in]namename for labeling the output
[in]runsnumber of times to run func
[in]funcfunction call to benchmark

Definition at line 44 of file benchmark.h.

Function Documentation

◆ benchmark_print_time()

void benchmark_print_time ( uint32_t time,
unsigned long runs,
const char * name )

Output the given time as well as the time per run on STDIO.

Parameters
[in]timeoverall runtime in us
[in]runsnumber of runs
[in]namename to label the output