EisFrei @lemmy.world
Ah yes. The speedup-loop.
https://thedailywtf.com/articles/The-Speedup-Loop90 0 Replytryptaminev 🇵🇸 🇺🇦 🇪🇺 @feddit.de
This is brilliant.
23 0 Reply
bangupjobasusual @sh.itjust.works I think some compilers will just drop that in the optimization step.
83 0 Replyryannathans @aussie.zone Real pain in the ass when you're in embedded and your carefully placed NOPs get stripped
28 0 Replyvrighter @discuss.tchncs.de asm("nop");
5 0 Reply
Midnight Wolf @lemmy.world
Homer: "oh yeah speed
holessleep"17 0 Replyjaybone @lemmy.world Sleep holes
3 0 Reply
Darkassassin07 @lemmy.ca
Tell the CPU to wait for you?
Na, keep the CPU busy with useless crap till you need it.
71 0 Replyjaybone @lemmy.world Fuck those other processes. I want to hear that fan.
27 0 Replyleclownfou @sh.itjust.works I paid good money for my fan, I want to know it's working!
4 0 Reply
Kogasa @programming.dev
Have you considered a career in middle management
25 0 Reply
aksdb @lemmy.world On microcontrollers that might be a valid approach.
26 0 Replykevincox @lemmy.ml
I've written these cycle-perfect sleep loops before.
It gets really complicated if you want to account for time spent in interrupt handlers.
11 0 Replyaksdb @lemmy.world Thankfully I didn't need high precision realtime. I just needed to wait a few seconds for serial comm.
2 0 Reply
Darkassassin07 @lemmy.ca
But then I gotta buy a space heater too...
1 0 ReplyYIj54yALOJxEsY20eU @lemm.ee Microcontrollers run 100% of the time even while sleeping.
4 0 Reply
Matty_r @programming.dev
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.
13 0 Replyhenfredemars @infosec.pub 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.
12 0 Reply
vcmj @programming.dev Its a thing. https://en.m.wikipedia.org/wiki/Busy_waiting
11 0 ReplyDr. Moose @lemmy.world Javascript enters chat:
await new Promise(r => setTimeout(r, 2000));
Which is somehow even worse.
11 1 Replysbv @sh.itjust.works As someone who likes to use the CPU, I don't think it's worse.
4 0 ReplyKairuByte @lemmy.dbzer0.com
I mean, it’s certainly better than pre-2015.
2 0 Reply
ExtraMedicated @lemmy.world I actually remember the teacher having us do this in high school. I tried it again a few years later and it didn't really work anymore.
5 0 Replysnaggen @programming.dev
On my first programming lesson, we were taught that 1 second sleep was
for i = 1 to 1000
😀, computers was not that fast back then...13 0 Replyferret @sh.itjust.works I mean maybe in an early interpreted language like BASIC… even the Intel 8086 could count to 1000 in a fraction of a second
3 0 Reply
aname @lemmy.one I can relate. We have breaks ate work too.
4 0 ReplySocsa @sh.itjust.works You gotta measure the latency of the first loop.
4 0 ReplyBronco1676 @lemmy.ml 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
2 0 ReplyNo_Ones_Slick_Like_Gaston @lemmy.world Sudo sleep
1 1 Reply