files/en-us/web/api/performanceentry/duration/index.md
{{APIRef("Performance API")}}{{AvailableInWorkers}}
The read-only duration property returns a {{domxref("DOMHighResTimeStamp","timestamp", "", "no-code")}} that is the duration of the {{domxref("PerformanceEntry","performance entry", "", "no-code")}}. The meaning of this property depends on the value of this entry's {{domxref("PerformanceEntry.entryType", "entryType")}}.
A {{domxref("DOMHighResTimeStamp")}} representing the duration of the {{domxref("PerformanceEntry","performance entry", "", "no-code")}}. 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 {{domxref("PerformanceEntry.entryType","entryType")}}:
event
startTime to the next rendering paint (rounded to the nearest 8ms).first-input
startTime to the next rendering paint (rounded to the nearest 8ms).longtask
measure
navigation
resource
For the following entry types, duration is not applicable, and in this case the value is always 0:
elementlargest-contentful-paintlayout-shiftmarkpainttaskattributionvisibility-stateThe 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}}
{{Compat}}