The Performance.now() method returns a DOMHighResTimeStamp, measured in milliseconds, accurate to one thousandth of a millisecond.
The value represented by DOMHighResTimeStamp varies according the context. Bear in mind the following points:
- In any context, the value is the value from
t0of the main context (thePerformanceTiming.navigationStartproperty) — main context, or any type of worker spawned from the main context (or another worker.) - In dedicated workers created from a
Windowcontext, the value in the worker will be lower thanperformance.now()in the window who spawned that worker. It used to be the same ast0of the main context, but this was changed. - In shared or service workers, the value in the worker might be higher than that of the main context because that window can be created after those workers.
Syntax
t = performance.now();
Example
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).
Specifications
| Specification | Status | Comment |
|---|---|---|
| High Resolution Time Level 2 The definition of 'Performance.now()' in that specification. |
Editor's Draft | Stricter definitions of interfaces and types. |
| High Resolution Time The definition of 'Performance.now()' in that specification. |
Recommendation | Initial definition |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 20.0 webkit 24.0 [1] |
15.0 (15.0) | 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 | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 4.0 | 25.0 | 15.0 (15.0) | 10.0 | No support | 9 |
| on Web workers | ? | ? | 34.0 (34.0) | ? | ? | ? |
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.
See also
- When milliseconds are not enough: performance.now() from HTML5 Rocks.