Ah yes. The speedup-loop.
https://thedailywtf.com/articles/The-Speedup-LoopThis is brilliant.
I think some compilers will just drop that in the optimization step.
Real pain in the ass when you’re in embedded and your carefully placed NOPs get stripped
asm(“nop”);
Homer: “oh yeah speed
holessleep”Sleep holes
This should be the new isEven()/isOdd(). Calculate the speed of the CPU and use that to determine how long it might take to achieve a ‘sleep’ of a required time.
I took an embedded hardware class where specifically we were required to manually calculate our sleeps or use interrupts and timers rather than using a library function to do it for us.
Its a thing. https://en.m.wikipedia.org/wiki/Busy_waiting
Javascript enters chat:
await new Promise(r => setTimeout(r, 2000));
Which is somehow even worse.
As someone who likes to use the CPU, I don’t think it’s worse.
I mean, it’s certainly better than pre-2015.
You gotta measure the latency of the first loop.
I can relate. We have breaks ate work too.
I just measured it, and this takes 0.17 seconds. And it’s really reliable, I added another zero to that number and it was 1.7 seconds