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

瀏覽器相容性

另見