Performance.now()

  • Revision slug: Web/API/Performance.now()
  • Revision title: Performance.now()
  • Revision id: 459979
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment Moved From Web/API/Performance.now to Web/API/Performance.now()

Revision Content

Syntax

var t = window.performance.now();

window.performance.now() returns a timestamp, measured in milliseconds, accurate to one thousandth of a millisecond.

This timestamp is equal to the number of milliseconds since the navigationStart attribute of the window.performance.timing interface.

Example

var t0 = window.performance.now();
doSomething();
var t1 = window.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 window.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 window.performance.now always increase at a constant rate, independent of the system clock (which might be adjusted manually or skewed by software like NTP).

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatChrome("20.0") }} {{ property_prefix("webkit") }}
{{ CompatChrome("24.0") }}
{{ CompatGeckoDesktop("15.0") }} 10.0 {{ CompatNo() }} {{ CompatNo() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} (Yes) {{ CompatGeckoMobile("15.0") }} 10.0 {{ CompatNo() }} {{ CompatNo() }}

See also

Specification

W3C High Resolution Time

Revision Source

<h2 id="Syntax">Syntax</h2>
<pre>
var t = window.performance.now();</pre>
<p><strong>window.performance.now() </strong>returns a timestamp, measured in milliseconds, accurate to one thousandth of a millisecond.</p>
<p>This timestamp is equal to the number of milliseconds since the <code>navigationStart </code>attribute of the <a href="/en-US/docs/Navigation_timing" title="/en-US/docs/Navigation_timing"><code>window.performance.timing</code></a> interface.</p>
<h2 id="Example">Example</h2>
<pre class="brush: js">
var t0 = window.performance.now();
doSomething();
var t1 = window.performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.")
</pre>
<p>Unlike other timing data available to JavaScript (for example <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Date/now" title="/en-US/docs/JavaScript/Reference/Global_Objects/Date/now"><code>Date.now</code></a>), the timestamps returned by <code>window.performance.now() </code>are not limited to one-millisecond resolution. Instead, they represent times as floating-point numbers with up to microsecond precision.</p>
<p>Also unlike <code>Date.now</code>, the values returned by <code>window.performance.now </code>always increase at a constant rate, independent of the system clock (which might be adjusted manually or skewed by software like NTP).</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatChrome("20.0") }} {{ property_prefix("webkit") }}<br />
          {{ CompatChrome("24.0") }}</td>
        <td>{{ CompatGeckoDesktop("15.0") }}</td>
        <td>10.0</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Chrome for Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatNo() }}</td>
        <td>(Yes)</td>
        <td>{{ CompatGeckoMobile("15.0") }}</td>
        <td>10.0</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li><a href="http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now" title="http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now">When milliseconds are not enough: performance.now() </a>from HTML5 Rocks</li>
</ul>
<h2 id="Specification">Specification</h2>
<p><a href="http://www.w3.org/TR/hr-time/" title="http://www.w3.org/TR/hr-time/">W3C High Resolution Time</a></p>
Revert to this revision