Performance API
Performance 接口可用于获取当前页面中与性能相关的信息。
性能条目特定于执行上下文。你可以通过 Window.performance 访问窗口中运行的代码的性能信息,通过 WorkerGlobalScope.performance 访问 worker 中运行的代码的性能信息。
实例属性
Performance 接口没有继承任何属性。
- Performance.navigation
- : PerformanceNavigation 对象提供了在指定的时间段里发生的操作相关信息,包括页面是加载还是刷新、发生了多少次重定向等等。Not available in workers.
- Performance.timing
- : PerformanceTiming 对象包含延迟相关的性能信息。Not available in workers.
- Performance.memory
- : 其是 Chrome 添加的一个非标准扩展,这个属性提供了一个可以获取到基本内存使用情况的对象。不应该使用这个非标准的 API。
- Performance.timeOrigin
- : 返回性能测量开始时的时间的高精度时间戳。
实例方法
Performance 接口没有继承任何方法。
- Performance.clearMarks()
- : 将给定的 mark 从浏览器的性能输入缓冲区中移除。
- Performance.clearMeasures()
- : 将给定的 measure 从浏览器的性能输入缓冲区中移除。
- Performance.clearResourceTimings()
- : 从浏览器的性能数据缓冲区中移除所有 PerformanceEntry.entryType 是 "
resource" 的 PerformanceEntry。
- : 从浏览器的性能数据缓冲区中移除所有 PerformanceEntry.entryType 是 "
- Performance.getEntries()
- : 基于给定的 filter 返回一个 PerformanceEntry 对象的列表。
- Performance.getEntriesByName()
- : 基于给定的 name 和 entry type 返回一个 PerformanceEntry 对象的列表。
- Performance.getEntriesByType()
- : 基于给定的 entry type 返回一个 PerformanceEntry 对象的列表
- Performance.mark()
- : 根据给出 name 值,在浏览器的性能输入缓冲区中创建一个相关的DOMHighResTimeStamp
- Performance.measure()
- : 在浏览器的指定 start mark 和 end mark 间的性能输入缓冲区中创建一个指定的 DOMHighResTimeStamp
- Performance.now()
- : 返回一个表示从性能测量时刻开始经过的毫秒数 DOMHighResTimeStamp
- Performance.setResourceTimingBufferSize()
- : 将浏览器的资源 timing 缓冲区的大小设置为 "
resource" PerformanceEntry.entryType PerformanceEntry 对象的指定数量
- : 将浏览器的资源 timing 缓冲区的大小设置为 "
- Performance.toJSON()
- : 其是一个 JSON 格式转化器,返回
Performance对象的 JSON 对象
- : 其是一个 JSON 格式转化器,返回
事件
使用 addEventListener() 或者将事件监听器赋给该接口的 oneventname 属性来监听这些事件。
- Performance.resourcetimingbufferfull_event
- : 在浏览器的资源计时缓冲区已满时触发。
规范
浏览器兼容性
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
