• sus@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      11 days ago

      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.

      • FooBarrington@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        10 days ago

        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!