Performance.now()

  • Revision slug: Web/API/Performance.now()
  • Revision title: Performance.now()
  • Revision id: 471347
  • Created:
  • Creator: mAyur
  • Is current revision? No
  • Comment

Revision Content

{{APIRef("Performance")}}

Summary

The Performance.now() method returns a {{domxref("DOMHighResTimeStamp")}}, measured in milliseconds, accurate to one thousandth of a millisecond equal to the number of milliseconds since the {{domxref("PerformanceTiming.navigationStart")}} property and the call to the method.

Syntax

t = performance.now();

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 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
{{SpecName('Highres Time', '#dom-performance-now', 'Performance.now()')}} {{Spec2('Highres Time')}} Initail defintion

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 {{ CompatOpera("15.0") }} {{ 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

Revision Source

<p>{{APIRef("Performance")}}</p>
<h2 id="Summary">Summary</h2>
<p>The <code><strong>Performance.now()</strong></code> method returns a {{domxref("DOMHighResTimeStamp")}}, measured in milliseconds, accurate to one thousandth of a millisecond equal to the number of milliseconds since the {{domxref("PerformanceTiming.navigationStart")}} property and the call to the method.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">
<em>t</em> = <em>performance</em>.now();</pre>
<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>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>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="Specifications">Specifications</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>{{SpecName('Highres Time', '#dom-performance-now', 'Performance.now()')}}</td>
      <td>{{Spec2('Highres Time')}}</td>
      <td>Initail defintion</td>
    </tr>
  </tbody>
</table>
<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>{{ CompatOpera("15.0") }}</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>
Revert to this revision