PerformanceEntry

The PerformanceEntry object encapsulates a single performance metric that is part of the performance timeline. A performance entry can be directly created by making a performance mark or measure (for example by calling the mark() method) at an explicit point in an application. Performance entries are also created in indirect ways such as loading a resource (such as an image).

PerformanceEntry instances will always be one of the following subtypes:

Note: This feature is available in Web Workers

Properties

PerformanceEntry.name Read only

A value that further specifies the value returned by the PerformanceEntry.entryType property. The value of both depends on the subtype. See property page for valid values.

PerformanceEntry.entryType Read only

A string representing the type of performance metric such as, for example, "mark". See property page for valid values.

PerformanceEntry.startTime Read only

A DOMHighResTimeStamp representing the starting time for the performance metric.

PerformanceEntry.duration Read only

A DOMHighResTimeStamp representing the time value of the duration of the performance event.

Methods

PerformanceEntry.toJSON()

Returns a JSON representation of the PerformanceEntry object.

Example

The following example checks all PerformanceEntry properties to see if the browser supports them and if so, shows their values.

const output = document.getElementById('output');

function printPerformanceEntries() {
  // Use getEntries() to get a list of all performance entries
  const entries = performance.getEntries();

  entries.forEach((entry, i) => {
    output.textContent += `\n PerformanceEntry[${i}] \n`;
    printPerformanceEntry(entry);
  });
}

function printPerformanceEntry(entry) {
  const properties = ["name",
                    "entryType",
                    "startTime",
                    "duration"];

  for (const prop of properties) {
    // Check each property
    if (prop in entry) {
      output.textContent += `${prop} = ${entry[prop]} \n`;
    } else {
      output.textContent += `${prop} is NOT supported \n`;
    }
  }
}

printPerformanceEntries();

Specifications

Specification
Performance Timeline
# dom-performanceentry

Browser compatibility

BCD tables only load in the browser