Skip to content

Commit

Permalink
sys/benchmark: remove BENCHMARK_SETUP()
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Feb 20, 2018
1 parent 26ad044 commit 5efd959
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
29 changes: 11 additions & 18 deletions sys/include/benchmark.h
Expand Up @@ -29,35 +29,28 @@
extern "C" {
#endif

/**
* @brief Prepare the current scope for running BENCHMARK_x() macros
*/
#define BENCHMARK_SETUP() \
unsigned state; \
unsigned time

/**
* @brief 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...
*
* @note BENCHMARK_SETUP() needs to be called in the same scope
*
* @param[in] name name for labeling the output
* @param[in] runs number of times to run @p func
* @param[in] func function call to benchmark
*/
#define BENCHMARK_FUNC(name, runs, func) \
state = irq_disable(); \
time = xtimer_now_usec(); \
for (unsigned long i = 0; i < runs; i++) { \
func; \
} \
time = (xtimer_now_usec() - time); \
irq_restore(state); \
benchmark_print_time(time, runs, name)
#define BENCHMARK_FUNC(name, runs, func) \
{ \
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); \
}

/**
* @brief Output the given time as well as the time per run on STDIO
Expand Down
1 change: 0 additions & 1 deletion tests/periph_gpio/main.c
Expand Up @@ -221,7 +221,6 @@ static int bench(int argc, char **argv)
}

puts("\nGPIO driver run-time performance benchmark\n");
BENCHMARK_SETUP();
BENCHMARK_FUNC("nop loop", runs, __asm__ volatile("nop"));
BENCHMARK_FUNC("gpio_set", runs, gpio_set(pin));
BENCHMARK_FUNC("gpio_clear", runs, gpio_clear(pin));
Expand Down

0 comments on commit 5efd959

Please sign in to comment.