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 接口没有继承任何属性。

Performance.navigation 只读 Not available to workers
PerformanceNavigation 对象提供了在指定的时间段里发生的操作相关信息,包括页面是加载还是刷新、发生了多少次重定向等等。
Performance.timing 只读 Not available to workers
PerformanceTiming 对象包含延迟相关的性能信息。
performance.memory
其是 Chrome 添加的一个非标准扩展,这个属性提供了一个可以获取到基本内存使用情况的对象。不应该使用这个非标准的 API。
Performance.timeOrigin 只读  
返回性能测量开始时的时间的高精度时间戳。

事件处理程序

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()
将浏览器的资源 timing 缓冲区的大小设置为 "resource" type performance entry 对象的指定数量
Performance.toJSON() Not available to workers
其是一个 JSON 格式转化器,返回 Performance 对象的 JSON 对象

规范

Specification Status Comment
High Resolution Time Level 3
timeOrigin
Editor's Draft Defines timeOrigin property.
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 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.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 6Edge Full support YesFirefox Full support 7IE Full support 9Opera Full support 15Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 7Opera Android Full support 15Safari iOS Full support 9Samsung Internet Android ?
clearMarksChrome Full support 43Edge Full support YesFirefox Full support 41IE Full support 10Opera Full support 33Safari Full support 11WebView Android Full support 46Chrome Android Full support 46Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 33Safari iOS Full support 11Samsung Internet Android ?
clearMeasuresChrome Full support 43Edge Full support YesFirefox Full support 41IE Full support 10Opera Full support 33Safari Full support 11WebView Android Full support 46Chrome Android Full support 46Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 33Safari iOS Full support 11Samsung Internet Android ?
clearResourceTimingsChrome Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support 11WebView Android Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Chrome Android Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support 11Samsung Internet Android ?
getEntriesChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera No support NoSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android No support NoSafari iOS Full support 11Samsung Internet Android ?
getEntriesByNameChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera No support NoSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android No support NoSafari iOS Full support 11Samsung Internet Android ?
getEntriesByTypeChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera No support NoSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android No support NoSafari iOS Full support 11Samsung Internet Android ?
markChrome Full support 43Edge Full support YesFirefox Full support 41IE Full support 10Opera Full support 33Safari Full support 11WebView Android Full support 46Chrome Android Full support 46Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 33Safari iOS Full support 11Samsung Internet Android ?
measureChrome Full support 43Edge Full support YesFirefox Full support 41IE Full support 10Opera Full support 33Safari Full support 11WebView Android Full support 46Chrome Android Full support 46Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 33Safari iOS Full support 11Samsung Internet Android ?
memory
Non-standard
Chrome Full support YesEdge ? Firefox No support NoIE ? Opera Full support YesSafari No support NoWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android No support NoOpera Android Full support YesSafari iOS No support NoSamsung Internet Android ?
navigation
Deprecated
Chrome Full support 10Edge Full support YesFirefox Full support 7IE Full support 9Opera Full support 15Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 7Opera Android No support NoSafari iOS Full support 9Samsung Internet Android ?
nowChrome Full support 24Edge Full support YesFirefox Full support 15
Notes
Full support 15
Notes
Notes In Firefox 57.0.4 the accuracy was reduced to 20 microseconds.
Notes In Firefox 59 the accuracy was reduced to 2 milliseconds.
IE Full support 10Opera Full support 15Safari Full support 8WebView Android Full support YesChrome Android Full support 25Edge Mobile Full support YesFirefox Android Full support 15
Notes
Full support 15
Notes
Notes In Firefox 57.0.4 the accuracy was reduced to 20 microseconds.
Notes In Firefox 59 the accuracy was reduced to 2 milliseconds.
Opera Android No support NoSafari iOS Full support 9Samsung Internet Android ?
onresourcetimingbufferfullChrome Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge ? Firefox Full support YesIE No support NoOpera No support NoSafari No support NoWebView Android Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Chrome Android Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile ? Firefox Android Full support YesOpera Android Full support YesSafari iOS No support NoSamsung Internet Android ?
setResourceTimingBufferSizeChrome Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari No support NoWebView Android Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Chrome Android Full support 46
Full support 46
No support ? — 57
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS No support NoSamsung Internet Android ?
timeOrigin
Experimental
Chrome Full support 62Edge ? Firefox Full support 59IE ? Opera Full support 49Safari No support NoWebView Android Full support 62Chrome Android Full support 62Edge Mobile ? Firefox Android Full support 59Opera Android Full support 49Safari iOS No support NoSamsung Internet Android ?
timing
Deprecated
Chrome Full support 6Edge Full support YesFirefox Full support 7IE Full support 9Opera Full support 15Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 7Opera Android Full support 15Safari iOS Full support 9Samsung Internet Android ?
toJSONChrome No support NoEdge Full support YesFirefox Full support 25IE ? Opera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile Full support YesFirefox Android Full support 25Opera Android No support NoSafari iOS No support NoSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

 

文档标签和贡献者

此页面的贡献者: zhangchen, Ende93, anjia, xgqfrms-GitHub, xtx1130, HuazhuLi, wenshin, teoli
最后编辑者: zhangchen,