| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since September 2017.
Note: This feature is available in Web Workers.
The PerformanceEntry object encapsulates a single performance metric that is part of the browser's performance timeline.
The Performance API offers built-in metrics which are specialized subclasses of PerformanceEntry. This includes entries for resource loading, event timing, and more.
A performance entry can also be created by calling the Performance.mark() or Performance.measure() methods at an explicit point in an application. This allows you to add your own metrics to the performance timeline.
The PerformanceEntry instances will always be one of the following subclasses:
LargestContentfulPaintLayoutShiftPerformanceEventTimingPerformanceLongAnimationFrameTimingPerformanceLongTaskTimingPerformanceMarkPerformanceMeasurePerformanceNavigationTimingPerformancePaintTimingPerformanceResourceTimingPerformanceScriptTimingPerformanceServerTimingTaskAttributionTimingVisibilityStateEntryPerformanceEntry.name Read onlyA string representing the name for a performance entry. The value depends on the subtype.
PerformanceEntry.entryType Read onlyA string representing the type of performance metric. For example, "mark" when PerformanceMark is used.
PerformanceEntry.startTime Read onlyA DOMHighResTimeStamp representing the starting time for the performance metric.
PerformanceEntry.duration Read onlyA DOMHighResTimeStamp representing the duration of the performance entry.
PerformanceEntry.toJSON()Returns a JSON representation of the PerformanceEntry object.
The following example creates PerformanceEntry objects that are of the types PerformanceMark and PerformanceMeasure.
The PerformanceMark and PerformanceMeasure subclasses inherit the duration, entryType, name, and startTime properties from PerformanceEntry and set them to their appropriate values.
// Place at a location in the code that starts login
performance.mark("login-started");
// Place at a location in the code that finishes login
performance.mark("login-finished");
// Measure login duration
performance.measure("login-duration", "login-started", "login-finished");
function perfObserver(list, observer) {
list.getEntries().forEach((entry) => {
if (entry.entryType === "mark") {
console.log(`${entry.name}'s startTime: ${entry.startTime}`);
}
if (entry.entryType === "measure") {
console.log(`${entry.name}'s duration: ${entry.duration}`);
}
});
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ entryTypes: ["measure", "mark"] });
| Specification |
|---|
| Performance Timeline # performanceentry |
This page was last modified on Nov 20, 2024 by MDN contributors.
PerformanceEntryEventCountsLargestContentfulPaintLayoutShiftLayoutShiftAttributionNotRestoredReasonDetailsNotRestoredReasonsPerformancePerformanceElementTimingPerformanceEventTimingPerformanceLongAnimationFrameTimingPerformanceLongTaskTimingPerformanceMarkPerformanceMeasurePerformanceNavigationPerformanceNavigationTimingPerformanceObserverPerformanceObserverEntryListPerformancePaintTimingPerformanceResourceTimingPerformanceScriptTimingPerformanceServerTimingPerformanceTimingTaskAttributionTimingVisibilityStateEntryWindow.performanceWorkerGlobalScope.performanceYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |