Demonstrate setInterval lag

The interval at which a setInterval's callback function is called can be much longer than the interval specified. This is especially the case in performance benchmarks, where setInterval's interval must NOT be relied upon to calculate the number of operations per interval.

This page demonstrates that when the time taken by setInterval's callback exceeds the requested interval, the callback will start to be called a lot less frequently than requested.

This page has a setInterval set to call its callback every 1 second. The callback paints a yellow rectangle to the canvas the number of times specified below. To start with, the number of seconds elapsed and the number of setInterval callback calls should stay roughly the same. However, if you increase the number of rectangles painted so that the callback takes longer than 1 second to complete (may need to be 100000 or greater), you'll see that the number of callback calls drops below one per second.

Number of rectangles drawn each callback:
Time elapsed:
setInterval callback calls: