`await` Slower Than It Should Be In Chrome `await` Slower Than It Should Be In Chrome google-chrome google-chrome

`await` Slower Than It Should Be In Chrome


You can easily observe a difference between an await expression and lack thereof. At the very least, you are asking the engine to look at the microtask queue, possibly doing other work that happened as a result of I/O completing. Given that, this cannot possibly be optimized into nothing.

If you truly wish to spin the CPU for a few milliseconds, don't write await.

Here's an example. It prints 1 2 3.

Promise.resolve().then(()=>console.log(2));(async()=>{  console.log(1);  await undefined;  console.log(3);})();

await undefined is not a "do-nothing" statement. It's JavaScript's cooperative multitasking.