Performance.measure()

The measure() method creates a named timestamp in the browser's performance entry buffer between two specified marks (known as the start mark and end mark, respectively). The named timestamp is referred to as a measure.

Note: This feature is available in Web Workers.

The measure can be retrieved by one of the Performance interface's getEntries*() methods (getEntries(), getEntriesByName() or getEntriesByType()).

The measure's performance entry will have the following property values:

Syntax

performance.measure(name, startMark, endMark);

Arguments

name
A DOMString representing the name of the measure.
startMark Optional
A DOMString representing the name of the measure's starting mark. May also be the name of a PerformanceTiming property.
endMark Optional
A DOMString representing the name of the measure's ending mark. May also be the name of a PerformanceTiming property.

Return value

void
 

Example

The following example shows how measure() is used to create a new measure performance entry in the browser's performance entry buffer.

// Start with one mark.
performance.mark("mySetTimeout-start");

// Wait some time.
setTimeout(function() {
  // Mark the end of the time.
  performance.mark("mySetTimeout-end");

  // Measure between the two different markers.
  performance.measure(
    "mySetTimeout",
    "mySetTimeout-start",
    "mySetTimeout-end"
  );

  // Get all of the measures out.
  // In this case there is only one.
  var measures = performance.getEntriesByName("mySetTimeout");
  var measure = measures[0];
  console.log("setTimeout milliseconds:", measure.duration)

  // Clean up the stored markers.
  performance.clearMarks();
  performance.clearMeasures();
}, 1000);

Specifications

Specification Status Comment
User Timing Level 2
The definition of 'measure()' in that specification.
Working Draft Clarifies measure() processing model.
User Timing
The definition of 'measure()' in that specification.
Recommendation Basic definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 43Edge Full support YesFirefox Full support 41IE Full support 10Opera Full support 33Safari Full support 11WebView Android Full support 46Chrome Android Full support 46Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 33Safari iOS Full support 11Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Last updated by: fscholz,