🎛️ Renames timing

This commit is contained in:
Rune Harlyk
2024-11-08 17:29:57 +01:00
parent 386f1c627d
commit ea5b16de0c
8 changed files with 7 additions and 7 deletions
+32
View File
@@ -0,0 +1,32 @@
#ifndef TIMING_H
#define TIMING_H
#define CONCAT(a, b) a##b
#define UNIQUE_VAR(base) CONCAT(base, __LINE__)
#define EXECUTE_EVERY_N_MS(n, code) \
do { \
static volatile unsigned long UNIQUE_VAR(lastExecution_) = 0; \
unsigned long currentMillis = millis(); \
if (UNIQUE_VAR(lastExecution_) == 0 || currentMillis - UNIQUE_VAR(lastExecution_) >= n) { \
code; \
UNIQUE_VAR(lastExecution_) = currentMillis; \
} \
} while (0)
#define TIME_IT(code) \
{ \
uint32_t time_it_start = micros(); \
code; \
uint32_t time_it_elapsed = micros() - time_it_start; \
if (time_it_elapsed < 1000) { \
ESP_LOGI("Time It", "Time elapsed: %lu microseconds", time_it_elapsed); \
} else if (time_it_elapsed < 1000000) { \
ESP_LOGI("Time It", "Time elapsed: %lu milliseconds", time_it_elapsed / 1000); \
} else { \
ESP_LOGI("Time It", "Time elapsed: %.2f seconds", time_it_elapsed / 1000000.0); \
} \
}
#endif