Performance 接口会给出某个页面的与时间相关的性能信息。
该类型对象可以通过调用只读属性 Window.performance 获得。
注意:该接口以及其属性存在于 Web Worker , 除了下面指出的情况。注意该接口部分还没有写入规范中(详细查看 Performance Timeline 和 User Timing 规范文档)。同时需要注意 Performance 时间标记和测量环境只能是当前 Web Worker 线程中,不能跨 Worker 标记时间,比如在新建的 Worker 线程中进行标记时间,将无法被主 Worker 线程获取。
属性
Performance 接口不从别的类继承属性。
Performance.navigation只读 Not available to workers- 是一个
PerformanceNavigation对象代表了页面浏览上下文的导航信息,比如获取资源时的重定向。 Performance.timing只读 Not available to workers- 是一个
PerformanceTiming对象包含了与延迟相关的性能信息。 -
事件
Performance.onresourcetimingbufferfull- 一个
EventTarget回调方法,当resourcetimingbufferfull事件触发时被调用。
方法
Performance 接口没有从别的类继承来的方法.
Performance.clearMarks()- 清除浏览器的performance缓存中已经存在的的标记
Performance.clearMeasures()- Removes the given measure from the browser's performance entry buffer.
Performance.clearResourceTimings()- Removes all
performance entrieswith aentryTypeof "resource" from the browser's performance data buffer. Performance.getEntries()- Returns a list of
PerformanceEntryobjects based on the given filter. Performance.getEntriesByName()- Returns a list of
PerformanceEntryobjects based on the given name and entry type. Performance.getEntriesByType()- Returns a list of
PerformanceEntryobjects of the given entry type. Performance.mark()- Creates a
timestampin the browser's performance entry bufferwith the given name. Performance.measure()- Creates a named
timestampin the browser's performance entry buffer between two specified marks (known as the start mark and end mark, respectively). Performance.now()- 返回一个
DOMHighResTimeStamp类实例表示距离页面开始请求到现在相差的毫秒数(即 Date.now() -Performance.timing.navigationStart)。 Performance.setResourceTimingBufferSize()- Sets the browser's resource timing buffer size to the specified number of "
resource"typeperformance entryobjects. Performance.toJSON()Not available to workers- Is a jsonizer returning a json object representing the
Performanceobject.
Specifications
| Specification | Status | Comment |
|---|---|---|
| High Resolution Time Level 2 toJSON() |
Candidate Recommendation | Defines toJson() method. |
| High Resolution Time Performance |
Recommendation | Defines now() method. |
| Navigation Timing Performance |
Recommendation | Defines timing and navigation properties. |
| Performance Timeline Time Level 2 Performance extensions |
Editor's Draft | 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 Performance extensions |
Editor's Draft | Clarifies mark(), clearMark(), measure() and clearMeasure() methods. |
| User Timing Performance extensions |
Recommendation | Defines mark(), clearMark(), measure() and clearMeasure() methods. |
Browser compatibility
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
Basic support (timing attribute) |
6.0 [1] | (Yes) | 7.0 (7.0) | 9.0 | 15.0 | 8 |
navigation attribute |
9 | ? | 7 (7) | 9.0 | 15 | 8 |
now() on regular context |
20.0 -webkit 24.0 |
? | 15.0 (15.0) | 10.0 | (Yes) | 8 |
now() in Web workers. |
33.0 | ? | 34.0 (34.0) | ? | (Yes) | 未实现 |
toJSON() |
未实现 | ? | 25.0 (25.0) | 9.0 | 未实现 | 未实现 |
getEntries(), getEntriesByType(), getEntriesByName() |
(Yes) | ? | (Yes) | (Yes) | (Yes) | 11 |
clearResourceTimings(), setResourceTimingBufferSize() |
(Yes) | ? | (Yes) | (Yes) | (Yes) | 未实现 |
onresourcetimingbufferfull |
(Yes) | ? | (Yes) | 未实现 | (Yes) | 未实现 |
mark(), clearMarks(), measure(), clearMeasure() |
43.0 | ? | 41 | 10 | 33 | 未实现 |
| Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | 7.0 (7.0) | 1.0 (7.0) | 9.0 | 15.0 | 9 | (Yes) |
navigation attribute |
未实现 | (Yes) | ? | 未实现 | 未实现 | 9.0 | (Yes) | 9 | (Yes) |
now() on regular context |
25.0 | ? | 15.0 (15.0) | 1.0 (15.0) | 10.0 | (Yes) | 9 | 20.0 webkit 25.0 |
|
now() in Web workers. |
未实现 | (Yes) | ? | 34.0 (34.0) | ? | ? | ? | ? | (Yes) |
toJSON() |
未实现 | 未实现 | ? | 25.0 (25.0) | 1.2 (25.0) | 10.0 | 未实现 | ? | 未实现 |
getEntries(), getEntriesByType(), getEntriesByName() |
4.4 | (Yes) | ? | 25.0 (25.0) | 1.2 (25.0) | 10.0 | 33 | 11 | 59 |
clearResourceTimings(), setResourceTimingBufferSize() |
未实现 | (Yes) | ? | (Yes) | (Yes) | (Yes) | 33 | 未实现 | (Yes) |
onresourcetimingbufferfull |
未实现 | (Yes) | ? | (Yes) | ? | 未实现 | 33 | 未实现 | (Yes) |
mark(), clearMarks(), measure(), clearMeasure() |
未实现 | 46.0 | ? | 42 | 42 | 10 | 33 | 未实现 | 46.0 |
[1] Member prefixed with webkit have been removed or deprecated.