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. More...
 

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. More...
 

Macro Definition Documentation

◆ BENCHMARK_FUNC

#define BENCHMARK_FUNC (   name,
  runs,
  func 
)
Value:
do { \
uint32_t _benchmark_time = ztimer_now(ZTIMER_USEC); \
for (unsigned long i = 0; i < runs; i++) { \
func; \
} \
_benchmark_time = (ztimer_now(ZTIMER_USEC) - _benchmark_time);\
benchmark_print_time(_benchmark_time, runs, name); \
} while (0)
ztimer_clock_t *const ZTIMER_USEC
Default ztimer microsecond clock.
static ztimer_now_t ztimer_now(ztimer_clock_t *clock)
Get the current time from a clock.
Definition: ztimer.h:600

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