性能

Baseline 广泛可用 *

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 2015 年 9 月以来,该特性已在各大浏览器中可用。

* 此特性的某些部分可能存在不同级别的支持。

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

Performance 接口提供对当前页面的性能相关信息的访问。

性能条目是每个执行上下文特有的。你可以通过 Window.performance 访问在窗口中运行的代码的性能信息,通过 WorkerGlobalScope.performance 访问在 worker 中运行的代码的性能信息。

EventTarget Performance

实例属性

Performance 接口不继承任何属性。

Performance.eventCounts 只读

一个 EventCounts 映射,其中包含按事件类型分派的事件数量。

Performance.navigation 只读 已弃用

一个旧版的 PerformanceNavigation 对象,它提供了关于 timing 中列出的操作的有用上下文,包括页面是加载还是刷新,发生了多少重定向等等。

Performance.timing 只读 已弃用

一个旧版的 PerformanceTiming 对象,包含与延迟相关的性能信息。

Performance.memory 只读 非标准 已弃用

这是 Chrome 中添加的非标准扩展,此属性提供一个具有基本内存使用信息的对象。不应使用此非标准 API。

Performance.timeOrigin 只读

返回性能测量的开始时间的高分辨率时间戳。

实例方法

Performance 接口不继承任何方法。

Performance.clearMarks()

从浏览器的性能条目缓冲区中移除指定的标记

Performance.clearMeasures()

从浏览器的性能条目缓冲区中移除指定的度量

Performance.clearResourceTimings()

从浏览器的性能数据缓冲区中移除所有 性能条目,这些条目的 entryType"resource"

Performance.getEntries()

根据给定的过滤器返回一个 PerformanceEntry 对象列表。

Performance.getEntriesByName()

根据给定的名称条目类型返回一个 PerformanceEntry 对象列表。

Performance.getEntriesByType()

返回给定条目类型PerformanceEntry 对象列表。

Performance.mark()

在浏览器的性能条目缓冲区中创建一个具有给定名称的 时间戳

Performance.measure()

在浏览器的性能条目缓冲区中,在两个指定的标记(分别称为开始标记结束标记)之间创建一个命名的 时间戳

Performance.measureUserAgentSpecificMemory() 实验性

估算 Web 应用程序(包括其所有 iframe 和 worker)的内存使用情况。

Performance.now()

返回一个 DOMHighResTimeStamp,表示自某个参考点以来的毫秒数。

Performance.setResourceTimingBufferSize()

将浏览器的资源计时缓冲区大小设置为指定数量的 "resource" type PerformanceEntry 对象。

Performance.toJSON()

返回 Performance 对象的 JSON 表示形式。

事件

使用 addEventListener() 或通过将事件监听器分配给此接口的 oneventname 属性来监听这些事件。

resourcetimingbufferfull

当浏览器的 资源计时缓冲区已满时触发。

规范

规范
高精度时间
# sec-performance
性能时间线
# extensions-to-the-performance-interface
资源时序
# sec-extensions-performance-interface
用户计时
# extensions-performance-interface

浏览器兼容性