This does the timeout and the interval method and calculates some metrics. The most important for me is the sum, which is the summed up errors against the expected triggering time.
This results in
setTimeout
Min -0.11596679687
Max 0.1708984375
Mean -1.98157337024
Sum 18.408203125
SD 1.73718663338
setInterval
Min -0.0244140625
Max -0.31127929687
Mean -2.17123413085
Sum -171.23413085937
SD 1.73305703021
This seems to hint to the timeout method accumulating only a tenth of the error the interval does with 100ms waiting time and 1000 tries.
I would expect the error to get smaller over time with the timeout method.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Some experiments on timeouts and intervals:
https://gist.github.com/halemmerich/c375d51646ee0a1036d76be810acfe6f
This does the timeout and the interval method and calculates some metrics. The most important for me is the sum, which is the summed up errors against the expected triggering time.
This results in
This seems to hint to the timeout method accumulating only a tenth of the error the interval does with 100ms waiting time and 1000 tries.
I would expect the error to get smaller over time with the timeout method.