node:perf_hooks

Node's [perf_hooks][nodejs-perf-hooks] module surface, importable through both ESM and CommonJS:

js
import perf from "node:perf_hooks";
// or
const perf = require("node:perf_hooks");

[nodejs-perf-hooks]: https://nodejs.org/api/perf_hooks.html

The module shares its per-realm performance timeline with globalThis.performance: a mark created through one is observable through the other, and perf.performance is identical (===) to globalThis.performance.

Exports

ExportTypeNotes
performancePerformanceThe same singleton as globalThis.performance.
now()() => numberEquivalent to performance.now().
mark(name, options?)(name, opts) => PerformanceMarkEquivalent to performance.mark.
measure(name, startOrOptions?, endMark?)(...) => PerformanceMeasureEquivalent to performance.measure.
getEntries()() => PerformanceEntry[]Equivalent to performance.getEntries.
getEntriesByName(name, type?)(...) => PerformanceEntry[]Equivalent to performance.getEntriesByName.
getEntriesByType(type)(type) => PerformanceEntry[]Equivalent to performance.getEntriesByType.
clearMarks(name?)(name?) => voidEquivalent to performance.clearMarks.
clearMeasures(name?)(name?) => voidEquivalent to performance.clearMeasures.
timeOriginnumberSame value as performance.timeOrigin.
nodeTimingPerformanceNodeTimingSee below. [SameObject].
PerformanceEntryconstructorSame identity as globalThis.PerformanceEntry.
PerformanceMarkconstructorSame identity as globalThis.PerformanceMark.
PerformanceMeasureconstructorSame identity as globalThis.PerformanceMeasure.
PerformanceObserverconstructorSame identity as globalThis.PerformanceObserver.
PerformanceObserverEntryListconstructorSame identity as globalThis.PerformanceObserverEntryList.
PerformanceNodeTimingconstructorNode-only entry constructor; not exposed as a global.
constantsobjectEmpty placeholder — Node ships an empty object here for users who run Object.keys(perf_hooks).includes('constants').
For the full semantics of each entry / observer interface, see the Performance reference. What follows is the Node-only addition.

PerformanceNodeTiming

Extends PerformanceEntry (entryType = "node", name = "node"). Captures realm-startup moments. Returned by perf_hooks.performance.nodeTiming. The same instance is referenced across reads ([SameObject]); it also appears in performance.getEntriesByType("node").

ts
interface PerformanceNodeTiming extends PerformanceEntry {
  readonly nodeStart: number;
  readonly v8Start: number;
  readonly environment: number;
  readonly bootstrapComplete: number;
  readonly loopStart: number;
  readonly loopExit: number;
  readonly idleTime: number;
}
In Elide:
FieldValueReason
nodeStartperformance.timeOriginThe closest analogue to "process start" available; captured at agent init.
v8Start0Truffle JS, not V8 — the field exists for compatibility but has no meaningful value here.
environmentperformance.timeOriginThe JS environment finishes initialising synchronously alongside the agent.
bootstrapCompleteperformance.timeOriginSame — bootstrap is synchronous.
loopStart0The embedder does not surface a discrete event-loop start moment.
loopExit0The loop has not exited yet for the lifetime of the realm.
idleTime0The embedder does not measure event-loop idleness.
The entry itself is constructed lazily on first read of nodeTiming — its values are static once captured, so a delayed first read does not lose information.

Compatibility with Node

  • require("node:perf_hooks").performance === globalThis.performance — yes, just like Node.
  • Constructors imported via the module are the same identity as the global ones — values produced one way are instanceof the other.
  • Async observer-callback delivery uses Elide's microtask checkpoint hook, matching the observable behaviour of Node's promise-microtask-bound delivery.
  • The legacy monitorEventLoopDelay / createHistogram / PerformanceResourceTiming surfaces are not implemented — the WebIDL source describes only the namespace members listed above.