benchmark.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017,2018 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #ifndef BENCHMARK_H
22 #define BENCHMARK_H
23 
24 #include <stdint.h>
25 
26 #include "irq.h"
27 #include "xtimer.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
44 #define BENCHMARK_FUNC(name, runs, func) \
45  { \
46  unsigned _benchmark_irqstate = irq_disable(); \
47  uint32_t _benchmark_time = xtimer_now_usec(); \
48  for (unsigned long i = 0; i < runs; i++) { \
49  func; \
50  } \
51  _benchmark_time = (xtimer_now_usec() - _benchmark_time);\
52  irq_restore(_benchmark_irqstate); \
53  benchmark_print_time(_benchmark_time, runs, name); \
54  }
55 
63 void benchmark_print_time(uint32_t time, unsigned long runs, const char *name);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif /* BENCHMARK_H */
70 
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.
xtimer interface definitions
IRQ driver interface.