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
.
measure
can be retrieved by one of the
性能
interfaces: (
getEntries()
,
getEntriesByName()
or
getEntriesByType()
).
measure
's
performance entry
will have the following property values:
entryType
- set to "
measure
".
名称
- set to the "
名称
" 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); performance.measure(name, startMark); performance.measure(name, startMark, endMark); performance.measure(name, undefined, 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. If it is omitted, then the start time will be the navigation start time.
DOMString
representing the name of the measure's ending mark. May also be the name of a
PerformanceTiming
property. If it is omitted, then the current time is used.
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);
| 规范 | 状态 | 注释 |
|---|---|---|
|
User Timing Level 2
The definition of 'measure()' in that specification. |
工作草案 |
Clarifies
measure()
processing model.
|
|
User Timing
The definition of 'measure()' in that specification. |
推荐 | Basic definition. |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
measure
|
Chrome
28
|
Edge 12 | Firefox 41 | IE 10 | Opera 33 | Safari 11 | WebView Android 46 |
Chrome Android
28
|
Firefox Android 42 | Opera Android 33 | Safari iOS 11 | Samsung Internet Android 1.5 |
完整支持
要求使用供应商前缀或不同名称。
性能