此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
Performance
Baseline Widely available *
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年9月.
* Some parts of this feature may have varying levels of support.
Performance 接口可用于获取当前页面中与性能相关的信息。
性能条目特定于执行上下文。你可以通过Window.performance 访问窗口中运行的代码的性能信息,通过WorkerGlobalScope.performance 访问 worker 中运行的代码的性能信息。
In this article
实例属性
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()基于给定的name 和entry type 返回一个
PerformanceEntry对象的列表。Performance.getEntriesByType()基于给定的entry type 返回一个
PerformanceEntry对象的列表Performance.mark()根据给出 name 值,在浏览器的性能输入缓冲区中创建一个相关的
timestampPerformance.measure()在浏览器的指定start mark 和 end mark 间的性能输入缓冲区中创建一个指定的
timestampPerformance.now()返回一个表示从性能测量时刻开始经过的毫秒数
DOMHighResTimeStampPerformance.setResourceTimingBufferSize()将浏览器的资源 timing 缓冲区的大小设置为 "
resource"typeperformance entry对象的指定数量Performance.toJSON()其是一个 JSON 格式转化器,返回
Performance对象的 JSON 对象
事件
使用addEventListener() 或者将事件监听器赋给该接口的oneventname 属性来监听这些事件。
resourcetimingbufferfull在浏览器的资源计时缓冲区已满时触发。