Performance
Performance
接口可以获取到当前页面中与性能相关的信息。它是 High Resolution Time API 的一部分,同时也融合了 Performance Timeline API、Navigation Timing API、 User Timing API 和 Resource Timing API。
该类型的对象可以通过调用只读属性 Window.performance
来获得。
注意:除了以下指出的情况外,该接口及其成员在 Web Worker
中可用。此外,还需注意,performance 的创建和衡量都是同一环境下的。即,如果你在主线程(或者其他 worker)中创建了一个 performance,那么它在另外的 worker 线程中是不可用的;反之亦然。
属性
Performance
接口没有继承任何属性。
-
Deprecated
Performance.navigation
只读 PerformanceNavigation
对象提供了在指定的时间段里发生的操作相关信息,包括页面是加载还是刷新、发生了多少次重定向等等。Not available in workers.-
Deprecated
Performance.timing
只读 PerformanceTiming
对象包含延迟相关的性能信息。Not available in workers.performance.memory
Non-Standard- 其是 Chrome 添加的一个非标准扩展,这个属性提供了一个可以获取到基本内存使用情况的对象。不应该使用这个非标准的 API。
Performance.timeOrigin
只读 Non-Standard- 返回性能测量开始时的时间的高精度时间戳。
-
事件处理程序
Performance.onresourcetimingbufferfull
- 一个回调的
EventTarget
,当触发resourcetimingbufferfull
事件的时候会被调用。
方法
Performance
接口没有继承任何方法。
Performance.clearMarks()
- 将给定的 mark 从浏览器的性能输入缓冲区中移除。
Performance.clearMeasures()
- 将给定的 measure 从浏览器的性能输入缓冲区中移除。
Performance.clearResourceTimings()
- 从浏览器的性能数据缓冲区中移除所有
entryType
是 "resource
" 的performance entries
。 Performance.getEntries()
- 基于给定的 filter 返回一个
PerformanceEntry
对象的列表。 Performance.getEntriesByName()
- 基于给定的 name 和 entry type 返回一个
PerformanceEntry
对象的列表。 Performance.getEntriesByType()
- 基于给定的 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 | Status | Comment |
---|---|---|
High Resolution Time Level 3 timeOrigin |
Editor's Draft | Defines timeOrigin property. |
High Resolution Time Level 2 toJSON() |
Recommendation | Defines toJson() method. |
High Resolution Time Performance |
Recommendation | Defines now() method. |
Navigation Timing Performance |
Recommendation | Defines timing and navigation properties. |
Performance Timeline Level 2 Performance extensions |
Candidate Recommendation | Changes getEntries() interface. |
Performance Timeline Performance extensions |
Recommendation | Defines getEntries() , getEntriesByType() and getEntriesByName() methods. |
Resource Timing Level 1 Performance extensions |
Candidate Recommendation | Defines clearResourceTimings() and setResourceTimingBufferSize() methods and the onresourcetimingbufferfull property. |
User Timing Level 2 Performance extensions |
Working Draft | Clarifies mark() , clearMark() , measure() and clearMeasure() methods. |
User Timing Performance extensions |
Recommendation | Defines mark() , clearMark() , measure() and clearMeasure() methods. |
浏览器兼容性
BCD tables only load in the browser