The performance.now()
method returns a DOMHighResTimeStamp
, measured in milliseconds, accurate to five thousandths of a millisecond (5 microseconds).
The returned value represents the time elapsed since the time origin.
Bear in mind the following points:
Window
context, the value in the worker will be lower than performance.now()
in the window who spawned that worker. It used to be the same as t0
of the main context, but this was changed.t = performance.now();
var t0 = performance.now(); doSomething(); var t1 = performance.now(); console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
Unlike other timing data available to JavaScript (for example Date.now
), the timestamps returned by Performance.now()
are not limited to one-millisecond resolution. Instead, they represent times as floating-point numbers with up to microsecond precision.
Also unlike Date.now()
, the values returned by Performance.now()
always increase at a constant rate, independent of the system clock (which might be adjusted manually or skewed by software like NTP). Otherwise, performance.timing.navigationStart + performance.now()
will be approximately equal to Date.now()
.
Specification | Status | Comment |
---|---|---|
High Resolution Time Level 2 The definition of 'performance.now()' in that specification. | Candidate Recommendation | Stricter definitions of interfaces and types. |
High Resolution Time The definition of 'performance.now()' in that specification. | Recommendation | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 20.0 webkit 24.0 [1] | (Yes) | 15.0 (15.0) [2] | 10.0 | 15.0 | 8.0 |
on Web workers | 33 | ? | 34.0 (34.0) | ? | ? | ? |
now() in a dedicated worker is now separate from the main context's now() . | ? | ? | 45.0 (45.0) | ? | ? | ? |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | 4.0 | 25.0 | (Yes) | 15.0 (15.0) [2] | 10.0 | No support | 9 | 25.0 |
on Web workers | ? | (Yes) | ? | 34.0 (34.0) | ? | ? | ? | (Yes) |
now() in a dedicated worker is now separate from the main context's now() . | ? | ? | ? | 45.0 (45.0) | ? | ? | ? | ? |
[1] Windows versions of Chrome 20 through 33 return performance.now()
only to millisecond precision.
[2] Starting with Firefox 57.0.4, the accuracy of this function has been reduced to 20 microseconds on the desktop and Android platforms, while the Mozilla team investigate a security issue related to the precise timing of events. The accuracy may be increased at a later date.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now