cm0002@lemmy.world to Programmer Humor@programming.dev · 6 months agotimeoutSortlemmy.mlimagemessage-square3linkfedilinkarrow-up11arrow-down10
arrow-up11arrow-down1imagetimeoutSortlemmy.mlcm0002@lemmy.world to Programmer Humor@programming.dev · 6 months agomessage-square3linkfedilink
minus-squareNat (she/they)@lemmy.blahaj.zonelinkfedilinkarrow-up0·6 months agoWait till you find out how the runtime manages multiple concurrent timers
minus-squaresus@programming.devlinkfedilinkarrow-up0·6 months agoit’s while (true) { let t = Date.now(); if (timeoutMap.has(t)) timeoutMap[t](); } of course. Clearly O(n). disclaimer Feel free to use it. I guarantee it is bug free. Comes with express warranty. This notice is legally binding.
minus-squareFooBarrington@lemmy.worldlinkfedilinkarrow-up1·6 months agoI found a way to optimize your code without affecting the result. By making it branchless, I was able to get my CPU to 100% utilization!
Wait till you find out how the runtime manages multiple concurrent timers
it’s
while (true) { let t = Date.now(); if (timeoutMap.has(t)) timeoutMap[t](); }of course. Clearly O(n).
disclaimer
Feel free to use it. I guarantee it is bug free. Comes with express warranty. This notice is legally binding.
I found a way to optimize your code without affecting the result. By making it branchless, I was able to get my CPU to 100% utilization!