Performance

Performance 接口可以获取到当前页面中与性能相关的信息。它是 High Resolution Time API 的一部分,同时也融合了 Performance Timeline API、Navigation Timing APIUser Timing APIResource Timing API

该类型的对象可以通过调用只读属性 Window.performance 来获得。

备注: 除了以下指出的情况外,该接口及其成员在 Web Worker 中可用。此外,还需注意,performance 的创建和衡量都是同一环境下的。即,如果你在主线程(或者其他 worker)中创建了一个 performance,那么它在另外的 worker 线程中是不可用的;反之亦然。

属性

Performance 接口没有继承任何属性。

已弃用 Performance.navigation 只读

PerformanceNavigation 对象提供了在指定的时间段里发生的操作相关信息,包括页面是加载还是刷新、发生了多少次重定向等等。Not available in workers.

已弃用 Performance.timing 只读

PerformanceTiming 对象包含延迟相关的性能信息。Not available in workers.

performance.memory 非标准

其是 Chrome 添加的一个非标准扩展,这个属性提供了一个可以获取到基本内存使用情况的对象。不应该使用这个非标准的 API。

Performance.timeOrigin 只读 非标准

返回性能测量开始时的时间的高精度时间戳。

事件处理程序

Performance.onresourcetimingbufferfull

一个回调的 EventTarget,当触发 resourcetimingbufferfull 事件的时候会被调用。

方法

Performance 接口没有继承任何方法。

Performance.clearMarks()

将给定的 mark 从浏览器的性能输入缓冲区中移除。

Performance.clearMeasures()

将给定的 measure 从浏览器的性能输入缓冲区中移除。

Performance.clearResourceTimings() (en-US)

从浏览器的性能数据缓冲区中移除所有 entryType 是 "resource" 的 performance entries

Performance.getEntries()

基于给定的 filter 返回一个 PerformanceEntry 对象的列表。

Performance.getEntriesByName()

基于给定的 nameentry type 返回一个 PerformanceEntry 对象的列表。

Performance.getEntriesByType() (en-US)

基于给定的 entry type 返回一个 PerformanceEntry 对象的列表

Performance.mark()

根据给出 name 值,在浏览器的性能输入缓冲区中创建一个相关的timestamp

Performance.measure()

在浏览器的指定 start mark 和 end mark 间的性能输入缓冲区中创建一个指定的 timestamp

Performance.now()

返回一个表示从性能测量时刻开始经过的毫秒数 DOMHighResTimeStamp

Performance.setResourceTimingBufferSize() (en-US)

将浏览器的资源 timing 缓冲区的大小设置为 "resource" type performance entry 对象的指定数量

Performance.toJSON()

其是一个 JSON 格式转化器,返回 Performance 对象的 JSON 对象

规范

Specification
High Resolution Time
# sec-performance
Performance Timeline
# extensions-to-the-performance-interface
Resource Timing
# sec-extensions-performance-interface
User Timing
# extensions-performance-interface

浏览器兼容性

BCD tables only load in the browser