Skip to content
VaelJS Blog

node:perf_hooks

Node-compatible high-resolution timing and performance measurement utilities (node:perf_hooks).

Available in vjs (vjs-lite omits monitorEventLoopDelay). Enabled by default unless --no-node-compat is passed.

import ... from "node:perf_hooks"
Since v0.0.0-alpha.2 vjs (V8) vjs-lite (QuickJS)
Cargo feature: node-compat (enabled by default; disable with --no-node-compat)
monitorEventLoopDelay is V8-only (vjs). performance, PerformanceEntry, PerformanceMark, PerformanceMeasure, PerformanceObserver, and constants run on both vjs and vjs-lite.
import { performance, PerformanceObserver } from "node:perf_hooks";
const obs = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
console.log(entry.name, entry.duration);
}
});
obs.observe({ entryTypes: ["measure"] });
performance.mark("start");
performance.mark("end");
performance.measure("work", "start", "end");
API Symbols
functionSince v0.0.0-alpha.2vjs only
export function monitorEventLoopDelay(options?: EventLoopDelayMonitorOptions): IntervalHistogram;

Create an event-loop delay histogram monitor (vjs only).

Parameters
NameTypeDescription
options optionalEventLoopDelayMonitorOptionsOptional sampling resolution configuration.
Returns
IntervalHistogram — An IntervalHistogram monitor (call .enable() to begin sampling).
classSince v0.0.0-alpha.2vjs & vjs-lite
export class PerformanceEntry {
  readonly name: string;
  readonly entryType: string;
  readonly startTime: number;
  readonly duration: number;
  readonly detail?: unknown;
  toJSON(): {
      name: string;
      entryType: string;
      startTime: number;
      duration: number;
      detail?: unknown;
    };
}

Base performance timeline entry record.

Properties
PropertyTypeDescriptionSince
name readonlystringEntry name.v0.0.0-alpha.2
entryType readonlystringEntry category (for example "mark" or "measure").v0.0.0-alpha.2
startTime readonlynumberHigh-resolution start time in milliseconds.v0.0.0-alpha.2
duration readonlynumberElapsed duration in milliseconds.v0.0.0-alpha.2
detail readonly optionalunknownOptional user-supplied detail payload.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
toJSON(): {
  name: string;
  entryType: string;
  startTime: number;
  duration: number;
  detail?: unknown;
};

Return a plain JSON-serializable representation of this entry.

Returns
{ name: string; entryType: string; startTime: number; duration: number; detail?: unknown; } — Entry summary object.
classSince v0.0.0-alpha.2vjs & vjs-lite
export class PerformanceMark extends PerformanceEntry {
  override readonly entryType: "mark";
  override readonly duration: 0;
  constructor(name: string, options?: PerformanceMarkOptions);
}

Performance timeline mark created by performance.mark().

Constructor
constructor(name: string, options?: PerformanceMarkOptions);

Construct a PerformanceMark.

Parameters
NameTypeDescription
namestringMark identifier.
options optionalPerformanceMarkOptionsOptional mark timestamp and detail payload.
Properties
PropertyTypeDescriptionSince
entryType readonly"mark"Always "mark".v0.0.0-alpha.2
duration readonly0Always 0.v0.0.0-alpha.2
classSince v0.0.0-alpha.2vjs & vjs-lite
export class PerformanceMeasure extends PerformanceEntry {
  override readonly entryType: "measure";
}

Performance timeline duration measurement created by performance.measure().

Properties
PropertyTypeDescriptionSince
entryType readonly"measure"Always "measure".v0.0.0-alpha.2
classSince v0.0.0-alpha.2vjs & vjs-lite
export class PerformanceObserver {
  static readonly supportedEntryTypes: readonly string[];
  constructor(callback: PerformanceObserverCallback);
  observe(options: PerformanceObserverObserveOptions): void;
  disconnect(): void;
  takeRecords(): PerformanceEntry[];
}

Observer receiving notifications as new PerformanceEntry records are added to the timeline.

Constructor
constructor(callback: PerformanceObserverCallback);

Construct a PerformanceObserver.

Parameters
NameTypeDescription
callbackPerformanceObserverCallbackCallback invoked with matching performance entries.
Properties
PropertyTypeDescriptionSince
supportedEntryTypes static readonlyreadonly string[]List of entry types supported by this runtime.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
observe(options: PerformanceObserverObserveOptions): void;

Begin observing entries matching options.

Parameters
NameTypeDescription
optionsPerformanceObserverObserveOptionsEntry type filter and buffering configuration.
Returns
void
methodSince v0.0.0-alpha.2
disconnect(): void;

Stop receiving performance entry notifications.

Returns
void
methodSince v0.0.0-alpha.2
takeRecords(): PerformanceEntry[];

Drain and return any queued entries not yet delivered to the callback.

Returns
PerformanceEntry[] — Array of buffered PerformanceEntry items.
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface PerformanceMarkOptions {
  detail?: unknown;
  startTime?: number;
}

Options accepted by performance.mark() and new PerformanceMark().

Properties
PropertyTypeDescriptionSince
detail optionalunknownArbitrary metadata attached to the mark entry.v0.0.0-alpha.2
startTime optionalnumberCustom high-resolution timestamp in milliseconds.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface PerformanceMeasureOptions {
  detail?: unknown;
  duration?: number;
  end?: number | string;
  start?: number | string;
}

Options accepted by performance.measure().

Properties
PropertyTypeDescriptionSince
detail optionalunknownArbitrary metadata attached to the measure entry.v0.0.0-alpha.2
duration optionalnumberExplicit duration in milliseconds.v0.0.0-alpha.2
end optionalnumber | stringEnd timestamp or mark name.v0.0.0-alpha.2
start optionalnumber | stringStart timestamp or mark name.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface PerformanceObserverEntryList {
  getEntries(): PerformanceEntry[];
  getEntriesByName(name: string, type?: string): PerformanceEntry[];
  getEntriesByType(type: string): PerformanceEntry[];
}

List of PerformanceEntry records delivered to a PerformanceObserver callback.

Methods
methodSince v0.0.0-alpha.2
getEntries(): PerformanceEntry[];

Return all observed entries in chronological order.

PerformanceObserverEntryList.getEntriesByName

Section titled “PerformanceObserverEntryList.getEntriesByName”
methodSince v0.0.0-alpha.2
getEntriesByName(name: string, type?: string): PerformanceEntry[];

Return observed entries matching name and optional type.

Parameters
NameTypeDescription
namestring—
type optionalstring—

PerformanceObserverEntryList.getEntriesByType

Section titled “PerformanceObserverEntryList.getEntriesByType”
methodSince v0.0.0-alpha.2
getEntriesByType(type: string): PerformanceEntry[];

Return observed entries matching type.

Parameters
NameTypeDescription
typestring—
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface PerformanceObserverObserveOptions {
  entryTypes?: string[];
  type?: string;
  buffered?: boolean;
}

Subscription options accepted by PerformanceObserver.observe().

Properties
PropertyTypeDescriptionSince
entryTypes optionalstring[]Array of entry types to observe.v0.0.0-alpha.2
type optionalstringSingle entry type to observe.v0.0.0-alpha.2
buffered optionalbooleanDeliver previously buffered entries immediately when true.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface PerformanceConstants {
  readonly NODE_PERFORMANCE_GC_MAJOR: number;
  readonly NODE_PERFORMANCE_GC_MINOR: number;
  readonly NODE_PERFORMANCE_GC_INCREMENTAL: number;
  readonly NODE_PERFORMANCE_GC_WEAKCB: number;
  readonly NODE_PERFORMANCE_GC_FLAGS_NO: number;
  readonly NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: number;
  readonly NODE_PERFORMANCE_GC_FLAGS_FORCED: number;
  readonly NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: number;
  readonly NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: number;
  readonly NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: number;
}

Numeric constants exposed on perf_hooks.constants.

Properties
PropertyTypeDescriptionSince
NODE_PERFORMANCE_GC_MAJOR readonlynumberMajor GC kind constant.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_MINOR readonlynumberMinor (scavenge) GC kind constant.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_INCREMENTAL readonlynumberIncremental GC kind constant.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_WEAKCB readonlynumberWeak-callback GC kind constant.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_FLAGS_NO readonlynumberNo GC flags constant.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED readonlynumberRetained-memory construct GC flag.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_FLAGS_FORCED readonlynumberForced GC flag.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING readonlynumberSynchronous phantom processing GC flag.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE readonlynumberAll-available-garbage GC flag.v0.0.0-alpha.2
NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY readonlynumberAll-external-memory GC flag.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface Performance {
  readonly timeOrigin: number;
  now(): number;
  mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
  measure(
      name: string,
      startOrMeasureOptions?: string | PerformanceMeasureOptions,
      endMark?: string,
    ): PerformanceMeasure;
  clearMarks(name?: string): void;
  clearMeasures(name?: string): void;
  getEntries(): PerformanceEntry[];
  getEntriesByName(name: string, type?: string): PerformanceEntry[];
  getEntriesByType(type: string): PerformanceEntry[];
  toJSON(): { timeOrigin: number };
}

Performance measurement interface exposed as perf_hooks.performance.

Properties
PropertyTypeDescriptionSince
timeOrigin readonlynumberHigh-resolution Unix epoch origin timestamp in milliseconds.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
now(): number;

Return current high-resolution monotonic timestamp in milliseconds.

Returns
number
methodSince v0.0.0-alpha.2
mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;

Record a named timestamp mark in the performance timeline.

Parameters
NameTypeDescription
namestring—
options optionalPerformanceMarkOptions—
methodSince v0.0.0-alpha.2
measure(
  name: string,
  startOrMeasureOptions?: string | PerformanceMeasureOptions,
  endMark?: string,
): PerformanceMeasure;

Record a duration measurement between marks or timestamps.

Parameters
NameTypeDescription
namestring—
startOrMeasureOptions optionalstring | PerformanceMeasureOptions—
endMark optionalstring—
methodSince v0.0.0-alpha.2
clearMarks(name?: string): void;

Remove named mark(s) or all marks from the timeline.

Parameters
NameTypeDescription
name optionalstring—
Returns
void
methodSince v0.0.0-alpha.2
clearMeasures(name?: string): void;

Remove named measure(s) or all measures from the timeline.

Parameters
NameTypeDescription
name optionalstring—
Returns
void
methodSince v0.0.0-alpha.2
getEntries(): PerformanceEntry[];

Return all recorded entries in chronological order.

methodSince v0.0.0-alpha.2
getEntriesByName(name: string, type?: string): PerformanceEntry[];

Return recorded entries matching name and optional type.

Parameters
NameTypeDescription
namestring—
type optionalstring—
methodSince v0.0.0-alpha.2
getEntriesByType(type: string): PerformanceEntry[];

Return recorded entries matching type.

Parameters
NameTypeDescription
typestring—
methodSince v0.0.0-alpha.2
toJSON(): { timeOrigin: number };

Return a JSON representation containing timeOrigin.

Returns
{ timeOrigin: number }
interfaceSince v0.0.0-alpha.2vjs only
export interface EventLoopDelayMonitorOptions {
  resolution?: number;
}

Options accepted by monitorEventLoopDelay().

Properties
PropertyTypeDescriptionSince
resolution optionalnumberSampling resolution in milliseconds (default 10).v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
export interface IntervalHistogram {
  readonly min: number;
  readonly max: number;
  readonly mean: number;
  readonly stddev: number;
  readonly count: number;
  readonly exceeds: number;
  readonly percentiles: Map<number, number>;
  enable(): boolean;
  disable(): boolean;
  reset(): void;
  percentile(percentile: number): number;
}

Histogram recording event-loop scheduling delay samples in nanoseconds.

Properties
PropertyTypeDescriptionSince
min readonlynumberMinimum observed delay in nanoseconds.v0.0.0-alpha.2
max readonlynumberMaximum observed delay in nanoseconds.v0.0.0-alpha.2
mean readonlynumberArithmetic mean delay in nanoseconds.v0.0.0-alpha.2
stddev readonlynumberStandard deviation of delay samples in nanoseconds.v0.0.0-alpha.2
count readonlynumberTotal number of recorded samples.v0.0.0-alpha.2
exceeds readonlynumberNumber of times the event-loop delay exceeded the histogram maximum.v0.0.0-alpha.2
percentiles readonlyMap<number, number>Map of recorded percentile buckets to nanosecond values.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
enable(): boolean;

Start collecting event-loop delay samples.

Returns
boolean
methodSince v0.0.0-alpha.2
disable(): boolean;

Stop collecting event-loop delay samples.

Returns
boolean
methodSince v0.0.0-alpha.2
reset(): void;

Reset all collected histogram statistics.

Returns
void
methodSince v0.0.0-alpha.2
percentile(percentile: number): number;

Return the delay value at the given percentile (0 < percentile <= 100).

Parameters
NameTypeDescription
percentilenumber—
Returns
number
typeSince v0.0.0-alpha.2vjs & vjs-lite
export type PerformanceObserverCallback = (
  list: PerformanceObserverEntryList,
  observer: PerformanceObserver,
) => void;

Callback invoked by a PerformanceObserver when new entries are recorded.

constSince v0.0.0-alpha.2vjs & vjs-lite
export const constants: PerformanceConstants;

Performance GC and entry-type constants.

constSince v0.0.0-alpha.2vjs & vjs-lite
export const performance: Performance;

High-resolution performance measurement API.

defaultSince v0.0.0-alpha.2vjs & vjs-lite
const _default: {
  /** `PerformanceEntry` constructor. @since 0.0.0-alpha.2 */
  PerformanceEntry: typeof PerformanceEntry;
  /** `PerformanceMark` constructor. @since 0.0.0-alpha.2 */
  PerformanceMark: typeof PerformanceMark;
  /** `PerformanceMeasure` constructor. @since 0.0.0-alpha.2 */
  PerformanceMeasure: typeof PerformanceMeasure;
  /** `PerformanceObserver` constructor. @since 0.0.0-alpha.2 */
  PerformanceObserver: typeof PerformanceObserver;
  /** Performance constants. @since 0.0.0-alpha.2 */
  readonly constants: PerformanceConstants;
  /** High-resolution performance timeline API. @since 0.0.0-alpha.2 */
  readonly performance: Performance;
  /** Event-loop delay histogram monitor factory. @since 0.0.0-alpha.2 */
  monitorEventLoopDelay: typeof monitorEventLoopDelay;
};
export default _default;
vjs-lite parity: monitorEventLoopDelay is available in vjs (V8) only and omitted from the default export in vjs-lite.

Default export object providing the node:perf_hooks API.