Performance: clearMeasures() 方法

Baseline 已广泛支持

此功能已成熟,可跨多种设备和浏览器版本使用。自 2017 年 9 月以来,它已在浏览器中提供。

注意:此功能在 Web Workers 中可用。

clearMeasures() 方法会从浏览器的性能时间轴中移除所有或指定的 PerformanceMeasure 对象。

语法

js
clearMeasures()
clearMeasures(name)

参数

name 可选

一个代表 PerformanceMeasure 对象 name 的字符串。如果省略此参数,则会移除所有 entryType"measure" 的条目。

返回值

无(undefined)。

示例

移除测量

要清理所有性能测量,或仅清理特定条目,请按以下方式使用 clearMeasures() 方法:

js
// Create a bunch of measures
performance.measure("from navigation");
performance.mark("a");
performance.measure("from mark a", "a");
performance.measure("from navigation");
performance.measure("from mark a", "a");
performance.mark("b");
performance.measure("between a and b", "a", "b");

performance.getEntriesByType("measure").length; // 5

// Delete just the "from navigation" measure entries
performance.clearMeasures("from navigation");
performance.getEntriesByType("measure").length; // 3

// Delete all of the measure entries
performance.clearMeasures();
performance.getEntriesByType("measure").length; // 0

规范

规范
用户计时
# dom-performance-clearmeasures

浏览器兼容性

另见