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.
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:
entryType
- set to "measure
".name
- set to the "name
" given when the measure was created.startTime
- set to the start mark timestamp
.duration
- set to a DOMHighResTimeStamp
that is the duration of the measure (typically, the end mark timestamp minus the start mark timestamp).performance.measure(name, startMark, endMark);
DOMString
representing the name of the measure.DOMString
representing the name of the measure's starting mark. May also be the name of a PerformanceTiming
property.DOMString
representing the name of the measure's ending mark. May also be the name of a PerformanceTiming
property.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);
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. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 43 | Yes | 41 | 10 | 33 | 11 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 46 | 46 | Yes | 42 | 33 | 11 | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure