The measure()
method creates a named timestamp
in the browser's performance entry buffer between marks, the navigation start time, or the current time. When measuring between two marks, there is a start mark and end mark, respectively. The named timestamp is referred to as a measure.
The measure
can be retrieved by one of the Performance
interfaces: (getEntries()
, getEntriesByName()
or getEntriesByType()
).
The measure
's performance entry
will have the following property values:
entryType
- set to "measure
".name
- set to the "name
" given when the measure was created.startTime
- set to the start marktimestamp
.duration
- set to aDOMHighResTimeStamp
that is the duration of the measure (typically, the end mark timestamp minus the start mark timestamp).
Note: This feature is available in Web Workers.
Syntax
performance.measure(name); performance.measure(name, startMark); performance.measure(name, startMark, endMark); performance.measure(name, undefined, 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 aPerformanceTiming
property. If it is omitted, then the start time will be the navigation start time. - endMark Optional
- A
DOMString
representing the name of the measure's ending mark. May also be the name of aPerformanceTiming
property. If it is omitted, then the current time is used.
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.
const markerNameA = "example-marker-a"
const markerNameB = "example-marker-b"
// Run some nested timeouts, and create a PerformanceMark for each.
performance.mark(markerNameA);
setTimeout(function() {
performance.mark(markerNameB);
setTimeout(function() {
// Create a variety of measurements.
performance.measure("measure a to b", markerNameA, markerNameB);
performance.measure("measure a to now", markerNameA);
performance.measure("measure from navigation start to b", undefined, markerNameB);
performance.measure("measure from the start of navigation to now");
// Pull out all of the measurements.
console.log(performance.getEntriesByType("measure"));
// Finally, clean up the entries.
performance.clearMarks();
performance.clearMeasures();
}, 1000);
}, 1000);
Specifications
Specification | Status | Comment |
User Timing Level 2The definition of 'measure()' in that specification. | Working Draft | Clarifies measure() processing model.
|
User TimingThe definition of 'measure()' in that specification. | Recommendation | Basic definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
measure
|
Chrome Full support 28 Full support 28 No support 25 — 28 Prefixed' Implemented with the vendor prefix: webkit |
Edge
Full support 12 |
Firefox
Full support 41 |
IE
Full support 10 |
Opera
Full support 33 |
Safari
Full support 11 |
WebView Android
Full support 46 |
Chrome Android Full support 28 Full support 28 No support 25 — 28 Prefixed' Implemented with the vendor prefix: webkit |
Firefox Android
Full support 42 |
Opera Android
Full support 33 |
Safari iOS
Full support 11 |
Samsung Internet Android
Full support 1.5 |
Legend
- Full support
- Full support
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
performance.measure() by Mozilla Contributors is licensed under CC-BY-SA 2.5.