measure()
方法在浏览器性能记录缓存中创建了一个名为时间戳
的记录来记录两个特殊标志位(通常称为开始标志和结束标志)。 被命名的时间戳
称为一次测量(measure)。
Note: 此特性在 Web Worker 中可用。
The measure
可以被Performance
接口 getEntries*()
中的方法检查到(getEntries()
, getEntriesByName()
或者 getEntriesByType()
).
The measure's
performance entry
will have the following property values:
语法
performance.measure(name, startMark, endMark);
参数
- name
- 一个
DOMString
, 代表测量的名字。 - startMark 可选
- 一个
DOMString
, 代表测量的开始标志名字。 May also be the name of aPerformanceTiming
property. - endMark 可选
- 一个
DOMString
, 代表测量的结束标志名字。May also be the name of aPerformanceTiming
property.
返回值
- void
例子
以下例子展示如何在浏览器性能记录缓存中使用 measure()
创建一个新的测量记录performance entry
。
// 以一个标志开始。
performance.mark("mySetTimeout-start");
// 等待一些时间。
setTimeout(function() {
// 标志时间的结束。
performance.mark("mySetTimeout-end");
// 测量两个不同的标志。
performance.measure(
"mySetTimeout",
"mySetTimeout-start",
"mySetTimeout-end"
);
// 获取所有的测量输出。
// 在这个例子中只有一个。
var measures = performance.getEntriesByName("mySetTimeout");
var measure = measures[0];
console.log("setTimeout milliseconds:", measure.duration)
// 清除存储的标志位
performance.clearMarks();
performance.clearMeasures();
}, 1000);
详细说明
详细说明 | 状态 | 评论 |
---|---|---|
User Timing Level 2 measure() |
Working Draft | Clarifies measure() processing model. |
User Timing measure() |
Recommendation | Basic definition. |
浏览器兼容性
BCD tables only load in the browser
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.