大网数据广告活动
Web 标准与前端开发

PerformanceEntry: duration property

· 52CE 我爱测

The read-only **`duration`** property returns a DOMHighResTimeStamp that is the duration of the PerformanceEntry. The meaning of this property depends on the value of this entry's PerformanceEntry.entryType.

Performance API

The read-only duration property returns a DOMHighResTimeStamp that is the duration of the PerformanceEntry. The meaning of this property depends on the value of this entry's PerformanceEntry.entryType.

Value

A DOMHighResTimeStamp representing the duration of the PerformanceEntry. If the duration concept doesn't apply for a particular performance metric, a duration of 0 is returned.

The meaning of this property depends on the value of this performance entry's PerformanceEntry.entryType:

  • event
    • : The time from the event's startTime to the next rendering paint (rounded to the nearest 8ms).
  • first-input
    • : The time from the first input event's startTime to the next rendering paint (rounded to the nearest 8ms).
  • longtask
    • : The elapsed time between the start and end of task, with a 1ms granularity.
  • measure
    • : The duration of the measure.
  • navigation
    • : The difference between the entry's PerformanceNavigationTiming.loadEventEnd and PerformanceEntry.startTime properties.
  • resource
    • : The entry's PerformanceResourceTiming/responseEnd value minus the entry's PerformanceEntry.startTime value.

For the following entry types, duration is not applicable, and in this case the value is always 0:

  • container
  • element
  • largest-contentful-paint
  • layout-shift
  • mark
  • paint
  • taskattribution
  • visibility-state

Examples

Using the duration property

The following example logs all observed performance entries with a duration larger than 0.

function perfObserver(list, observer) {
  list.getEntries().forEach((entry) => {
    if (entry.duration > 0) {
      console.log(`${entry.name}'s duration: ${entry.duration}`);
    }
  });
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ entryTypes: ["measure", "mark", "resource"] });

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。