The following code uses setInterval
to increment tick
once every 16ms and logs out the number of ticks per second. I'm expecting this to report ~60 ticks per second (as 1000ms / 16ms = ~60) but instead I'm seeing about 35-40. This is on a powerful windows desktop under minimal load (node v14.5.4). Running the same code in the browser produces the expected results.
let lastTick = 0;
let tick = 0;
setInterval(()=>{
tick++;
}, 16);
setInterval(()=>{
console.log("ticks per second: " + (tick-lastTick));
lastTick = tick;
}, 1000);
What am I missing?
Update
So running with node --inspect and then profiling the javascript boosts the values up 60 per second, but only while the profiler is running. Must be some sort of strange CPU throttling on low CPU processes, but I can't find any cause.