Fix esp32 hardware timer performance #2455
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fix poor performance of hwtimer2 on ESP32 by using hardware directly.
It also fixes code so it can be used from C.
How many loop iterations can we achieve in 100 ms ?
ESP32
Using millis(), managed 105418 iterations, average loop time = 949ns (152 CPU cycles)
Using micros(), managed 102942 iterations, average loop time = 971ns (155 CPU cycles)
Using PolledTimer:
BEFORE: managed 135827 iterations, average loop time = 736ns (118 CPU cycles)
AFTER: managed 921085 iterations, average loop time = 109ns (17 CPU cycles)
ESP32C3
Using millis(), managed 98837 iterations, average loop time = 1012ns (162 CPU cycles)
Using micros(), managed 123863 iterations, average loop time = 807ns (129 CPU cycles)
Using PolledTimer:
BEFORE: managed 136670 iterations, average loop time = 732ns (117 CPU cycles)
AFTER: managed 551882 iterations, average loop time = 181ns (29 CPU cycles)
ESP32S2
Using millis(), managed 68260 iterations, average loop time = 1465ns (234 CPU cycles)
Using micros(), managed 68921 iterations, average loop time = 1451ns (232 CPU cycles)
Using PolledTimer:
AFTER: managed 528409 iterations, average loop time = 189ns (30 CPU cycles)