Você está lendo a versão em inglês deste conteúdo porque ainda não há uma tradução para este idioma. Ajude-nos a traduzir este artigo!
O método performance.now()
retorna DOMHighResTimeStamp
, medido em milisegundos, com precisão de cinco milésimos de milissegundo (5 microsegundos).
O valor retornado representa o tempo decorrido desde o time origin (the PerformanceTiming.navigationStart
property). Em um web worker, o tempo inicial é o momento em que o contexto da execução(e.g. thread ou processo) é criado. Em uma janela, é o tempo em que o usuário iniciou a navegação neste documento. Tenha em mente que:
- Em workers dedicados criados do
Window
, o valor neste worker será inferior aperformance.now()
na window que gerou este worker. Normalmente é o mesmo quet0
no contexto principal, mas esse valor foi alterado. - Em shared workers ou service workers, o valor do worker pode ser maior em relação ao contexto principal poir estas janelas podem ser criadas depois destes workers.
Sintaxe
t = performance.now();
Exemplo
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()
.
Especificações
Specification | Status | Comment |
---|---|---|
High Resolution Time Level 2 The definition of 'performance.now()' in that specification. |
Candidata a Recomendação | Stricter definitions of interfaces and types. |
High Resolution Time The definition of 'performance.now()' in that specification. |
Recomendação | Initial definition |
Compatibilidade de Navegadores
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 20.0 webkit 24.0 [1] |
(Yes) | 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 | 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) | 10.0 | Não suportado | 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.
Veja também
- When milliseconds are not enough: performance.now() from HTML5 Rocks.