performance, PerformanceObserver, and the PerformanceEntry classes are globals and follow the
User Timing and
Performance Timeline specs.
Example
js
// performance.mjs
const start = performance.now();
performance.mark("parse:start");
JSON.parse(JSON.stringify(Array.from({ length: 1000 }, (_, i) => ({ i }))));
performance.mark("parse:end", { detail: { rows: 1000 } });
const measure = performance.measure("parse", "parse:start", "parse:end");
console.log(measure.entryType, measure.name, measure.duration >= 0);
console.log(performance.getEntriesByName("parse:end")[0].detail.rows);
console.log(performance.now() >= start, typeof performance.timeOrigin);
utf-8 · js · Lines: 10
elide run performance.mjs prints:
text
measure parse true
1000
true number
utf-8 · text · Lines: 3
Differences from browsers
performanceand node:perf_hooks share one timeline.PerformanceObserver.supportedEntryTypesismark,measure,node, andfunction.- Mark and measure
detailvalues are cloned as in Web Messaging; functions throwDataCloneError.
Reference
Status: Full · Not measured · since 1.1.0
Exports
| Export | Kind | Status | Notes |
|---|---|---|---|
PerformanceEntry | class | Full | name, entryType, startTime, duration, detail, toJSON() |
PerformanceMark | class | Full | detail |
PerformanceMeasure | class | Full | detail |
PerformanceObserverEntryList | class | Full | getEntries(), getEntriesByName(), getEntriesByType() |
PerformanceObserver | class | Full | observe(), disconnect(), takeRecords(), PerformanceObserver. |
Performance | class | Full | now(), timeOrigin, mark(), measure(), getEntries(), getEntriesByName(), getEntriesByType(), clearMarks(), clearMeasures(), toJSON() |