Performance

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

* Some parts of this feature may have varying levels of support.

Performance 接口可用于获取当前页面中与性能相关的信息。

性能条目特定于执行上下文。你可以通过 Window.performance 访问窗口中运行的代码的性能信息,通过 WorkerGlobalScope.performance 访问 worker 中运行的代码的性能信息。

EventTarget Performance

实例属性

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()

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

Performance.getEntries()

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

Performance.getEntriesByName()

基于给定的 nameentry 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()

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

事件

使用 addEventListener() 或者将事件监听器赋给该接口的 oneventname 属性来监听这些事件。

resourcetimingbufferfull

在浏览器的资源计时缓冲区已满时触发。

规范

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

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Performance
clearMarks
clearMeasures
clearResourceTimings
eventCounts
getEntries
getEntriesByName
getEntriesByType
mark
markOptions parameter
Returns PerformanceMark
measure
measureOptions parameter
Returns PerformanceMeasure
measureUserAgentSpecificMemory
Experimental
memory
DeprecatedNon-standard
navigation
Deprecated
now
resourcetimingbufferfull event
setResourceTimingBufferSize
timeOrigin
timing
Deprecated
toJSON

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
Uses a non-standard name.
Requires a vendor prefix or different name for use.
Has more compatibility info.