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:
{ \
unsigned _benchmark_irqstate = irq_disable(); \
uint32_t _benchmark_time = xtimer_now_usec(); \
for (unsigned long i = 0; i < runs; i++) { \
func; \
} \
_benchmark_time = (xtimer_now_usec() - _benchmark_time);\
irq_restore(_benchmark_irqstate); \
benchmark_print_time(_benchmark_time, runs, name); \
}
static uint32_t xtimer_now_usec(void)
get the current system time in microseconds since start
const char * name
Definition: lua_builtin.h:61
unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.

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