#define DEBUG
#define MAX(a,b) (((a) > (b) ) ? (a) : (b))
#define MIN(a,b) (((a) < (b) ) ? (a) : (b))
#define CONCAT(a, b) a ## b
#define UNIQUENAME(prefix) CONCAT(prefix, __LINE__)
#ifdef DEBUG
#define TIMEIT(block) do { \
static uint32_t UNIQUENAME(max_) = 0; \
static uint32_t UNIQUENAME(min_) = (uint32_t)(-1); \
static uint32_t UNIQUENAME(cnt_) = 0; \
static uint32_t UNIQUENAME(sum_) = 0; \
uint32_t UNIQUENAME(t_) = -micros(); \
{ block; } \
UNIQUENAME(t_) += micros(); \
UNIQUENAME(max_) = MAX(UNIQUENAME(max_), t); \
UNIQUENAME(min_) = MIN(UNIQUENAME(min_), t); \
UNIQUENAME(cnt_) ++; \
UNIQUENAME(sum_) += t; \
printf("[DBG] " __FILE__ "(%u): run #%u in %6u us (min/avg/max %6u/%6u/%6u)\n", \
__LINE__, UNIQUENAME(cnt_), t, UNIQUENAME(min_), UNIQUENAME(sum_)/UNIQUENAME(cnt_), UNIQUENAME(max_)); \
} while (0)
#else
#define TIMEIT(block) do { block; } while (0)
#endif
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
}
void loop() {
TIMEIT(
for (int i = 0; i < 2; i++) {
Serial.printf("Hello %u at %09u\n", i, millis());
}
);
TIMEIT(
delay(10);
);
delay(990);
}