Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
benchmark.h
Go to the documentation of this file.
1 
19 #ifndef BENCHMARK_H
20 #define BENCHMARK_H
21 
23 static uint32_t _start, _baseline = 0;
24 static uint32_t _benchmark;
25 
27 inline void noop() __attribute__((always_inline));
28 inline void noop() { __asm__ __volatile__("nop"); }
29 
34 #define BENCHMARK_BASELINE(scale) \
35  Serial.flush(); \
36  _start = micros(); \
37  for (int _i = 1; _i; _i--, _baseline = micros() - _start - _baseline) \
38  for (int _j = scale; _j; _j--, noop())
39 
52 #define BENCHMARK(msg,scale) \
53  Serial.print(F(msg ": ")); \
54  Serial.flush(); \
55  _start = micros(); \
56  for (int _i = 1; _i; _i--, _benchmark = micros() - _start - _baseline,\
57  Serial.println(_benchmark / (float) scale, 3)) \
58  for (int _j = scale; _j; _j--, noop())
59 
70 #define MEASURE(expr) BENCHMARK(#expr,1) expr
71 
72 #endif
static uint32_t _benchmark
Definition: benchmark.h:24
void noop()
Definition: benchmark.h:28
static uint32_t _start
Definition: benchmark.h:23
static uint32_t _baseline
Definition: benchmark.h:23