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 
9 #pragma once
10 
23 #include <stdint.h>
24 
25 #include "irq.h"
26 #include "ztimer/stopwatch.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
43 #define BENCHMARK_FUNC(name, runs, func) \
44  do { \
45  ztimer_stopwatch_t timer = { .clock = ZTIMER_USEC }; \
46  ztimer_stopwatch_start(&timer); \
47  for (unsigned long i = 0; i < runs; i++) { \
48  func; \
49  } \
50  benchmark_print_time(ztimer_stopwatch_measure(&timer), runs, name); \
51  ztimer_stopwatch_stop(&timer); \
52  } while (0)
53 
61 void benchmark_print_time(uint32_t time, unsigned long runs, const char *name);
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
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.
IRQ driver interface.