Since August 2010, the Web Performance Working Group has quietly but steadily added various timing information in the Open Web Platform. We introduced the performance attribute on the Window object, and are extending it since then using several specifications. The first article introduced Navigation Timing. This article introduces High Resolution Time.
High Resolution Time
For certain tasks,
Date.now() may not be sufficient, such as accurately measuring the elapsed time of navigation, calculating the frame rate of a script based animation, or synchronization between audio and animation.
High Resolution Time defines
window.performance.now(). The returned time value represents a number of milliseconds accurate to a thousandth of a millisecond (at most) and relative to the start of the navigation of the document (see the
window.performance.navigationStart attribute). Unlike values returned by
Date.now(), the difference between any two chronologically recorded time values returned from the now method cannot be negative.
var t1 = window.performance.now(); myTask(); var t2 = window.performance.now(); alert("myTask took " + (t2 - t1) + "ms"); // guaranteed to be >= 0
The November 2012 implementation report shows that this is supported in Internet Explorer, Chrome and Firefox.