I have always thought that timestamp used by requestAnimationFrame is the same as usual timestamp in JavaScript, that is number of milliseconds since January 1st, 1970. Today I have captured the timestamps to verify and found that the RAF timestamp are probably measured since the start of page loading. What precisely are the timestamps measured from?
The test code:
<p id="output"></p>
var i = 0;
var start = null;
var times = [];
var dur = 5000;
function step(timestamp) {
if (start===null) start = timestamp;
times[i++] = timestamp;
if (timestamp-start<=dur) {
requestAnimationFrame(step);
} else {
document.getElementById('output').innerHTML = times.join('<br>');
}
}
requestAnimationFrame(step);
gives results like this:
158.52126457412882
183.12243595205535
199.52116819316421
...
in all RAF capable browsers.
It's a DOMHighResTimeStamp
or a high-resolution timestamp (the same you get with window.performance.now()
).
The time stamp is:
current time for when requestAnimationFrame starts to fire callbacks.
The main difference between an ordinary timestamp and high-res timestamp is:
DOMTimeStamp only has millisecond precision, but DOMHighResTimeStamp
has a minimal precision of ten microseconds.
Note: some browsers do not implement this aspect of rAF yet and may give you faulty or no value as argument.
Some resources:
- requestAnimationFrame
- DOMHighResTimeStamp
Finally, I found the answer in an article by Paul Irish and the specification of High Resolution time:
requestAnimationFrame API: now with sub-millisecond precision
High Resolution Time
The rAF time is "measured relative to the start of navigation of the document", that is relative to the "navigationStart attribute of the PerformanceTiming interface".
MDN says:
The callback has one single argument, a DOMHighResTimeStamp, which
indicates the current time (the time returned from performance.now() )
And this is what performance.now() returns:
The returned value represents the time elapsed since the time origin.
The time origin is a standard time which is considered to be the
beginning of the current document's lifetime.