高分辨率时间 standard defines a 性能 interface that supports client-side latency measurements within applications. The 性能 interfaces are considered high resolution because they are accurate to a thousandth of a millisecond (subject to hardware or software constraints). The interfaces support a number of use cases including calculating frame-rates (potentially important in animations) and benchmarking (such as the time to load a resource).

Since a platform's system clock is subject to various skews (such as NTP adjustments), the interfaces support a monotonic clock i.e. a clock that is always increasing. As such, the 性能 API defines a DOMHighResTimeStamp type rather than using the Date.now() 接口。

DOMHighResTimeStamp

DOMHighResTimeStamp type, as its name implies, represents a high resolution point in time. This type is a double and is used by the performance interfaces. The value could be a discrete point in time or the difference in time between two discrete points in time.

The unit of DOMHighResTimeStamp is milliseconds and should be accurate to 5 µs (microseconds). However, If the browser is unable to provide a time value accurate to 5 microseconds (because, for example, due to hardware or software constraints), the browser can represent the value as a time in milliseconds accurate to a millisecond.

方法

性能 interface has two methods. The now() 方法返回 DOMHighResTimeStamp whose value that depends on the navigation start and scope. If the scope is a window, the value is the time the browser context was created and if the scope is a worker , the value is the time the worker was created.

toJSON() method returns a serialization of the 性能 object, for those attributes that can be serialized.

特性

性能 interface has two properties. The timing 特性返回 PerformanceTiming object containing latency-related performance information such as the start of navigation time, start and end times for redirects, start and end times for responses, etc.

navigation 特性返回 PerformanceNavigation object representing the type of navigation that occurs in the given browsing context, such as the page was navigated to from history, the page was navigated to by following a link, etc.

接口

性能

Provides methods and properties containing timing-related performance information for the given page.

PerformanceEntry

Provides methods and properties the encapsulate a single performance metric that is part of the performance timeline.

PerformanceFrameTiming

Provides methods and properties containing frame timing data about the browser's event loop.

PerformanceMark
An abstract interface for performance entries 采用 entry type of " mark ". Entries of this type are created by calling performance.mark() to add a named DOMHighResTimeStamp (the mark) to the browser's performance timeline.
PerformanceMeasure
An abstract interface for performance entries 采用 entry type of " measure ". Entries of this type are created by calling performance.measure() to add a named DOMHighResTimeStamp (the measure) between two marks to the browser's performance timeline.
PerformanceNavigationTiming
Provides methods and properties to store and retrieve high resolution timestamps or metrics regarding the browser's document navigation events.
PerformanceObserver
Provides methods and properties used to observe performance measurement events and be notified of new performance entries as they are recorded in the browser's performance timeline.
PerformanceResourceTiming

Provides methods and properties for retrieving and analyzing detailed network timing data regarding the loading of an application's resources.

规范

规范 状态 注释
高分辨率时间 推荐 初始定义。
High Resolution Time Level 2 推荐 添加 性能 attribute on Window and WorkerGlobalScope .
High Resolution Time Level 3 编者草案 添加 timeOrigin 特性到 性能 接口。
Frame Timing 草案 添加 PerformanceFrameTiming 接口。
导航计时 推荐 添加 PerformanceTiming and PerformanceNavigation interfaces. Adds timing and navigation properties to the 性能 接口。
Navigation Timing Level 2 工作草案 添加 PerformanceNavigationTiming interface. Obsolete's the the PerformanceTiming interface, the PerformanceNavigation interface, as well as the timing and navigation properties to the 性能 接口。
性能时间线 推荐 添加 PerformanceEntry interface, the PerformanceEntryList type, as well as the getEntries() , getEntriesByType() ,和 getEntriesByName() 方法在 性能 接口。
Performance Timeline Level 2 候选推荐 Adds serializer to the PerformanceEntry interface as well as adding the PerformanceObserver interface and callback
Resource Timing Level 1 候选推荐 添加 PerformanceResourceTiming interface. Adds the clearResourceTimings() method, the setResourceTimingBufferSize() method, and the onresourcetimingbufferfull event handler to the 性能 interface. Also adds the Timing-Allow-Origin 响应头。
Resource Timing Level 2 工作草案 添加 nextHopProtocol , workerStart , transferSize , encodedBodySize ,和 decodedBodySize properties to the PerformanceResourceTiming 接口。
Resource Timing Level 3 编者草案
User Timing 推荐 添加 mark() , clearMarks() , measure() and clearMeasures() methods to the 性能 interface. Adds the PerformanceMark and PeformanceMeasure 接口。
User Timing Level 2 工作草案

实现状态

As shown in the 性能 接口的 浏览器兼容性 table, most of these interfaces are broadly implemented by desktop browsers.

To test your browser's support for the 性能 interface, run the perf-api-support 应用程序。

另请参阅

元数据

  • 最后修改: