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"
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.Example
Section titled “Example”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");PerformanceEntryv0.0.0-alpha.2PerformanceMarkv0.0.0-alpha.2performance.mark().PerformanceMeasurev0.0.0-alpha.2performance.measure().PerformanceObserverv0.0.0-alpha.2PerformanceEntry records are added to the timeline.PerformanceMarkOptionsv0.0.0-alpha.2performance.mark() and new PerformanceMark().PerformanceMeasureOptionsv0.0.0-alpha.2performance.measure().PerformanceObserverEntryListv0.0.0-alpha.2PerformanceEntry records delivered to a PerformanceObserver callback.PerformanceObserverObserveOptionsv0.0.0-alpha.2PerformanceObserver.observe().PerformanceConstantsv0.0.0-alpha.2perf_hooks.constants.Performancev0.0.0-alpha.2perf_hooks.performance.EventLoopDelayMonitorOptionsvjs onlyv0.0.0-alpha.2monitorEventLoopDelay().IntervalHistogramvjs onlyv0.0.0-alpha.2Functions
Section titled “Functions”monitorEventLoopDelay
Section titled “monitorEventLoopDelay”export function monitorEventLoopDelay(options?: EventLoopDelayMonitorOptions): IntervalHistogram;
Create an event-loop delay histogram monitor (vjs only).
| Name | Type | Description |
|---|---|---|
options optional | EventLoopDelayMonitorOptions | Optional sampling resolution configuration. |
Classes
Section titled “Classes”PerformanceEntry
Section titled “PerformanceEntry”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.
| Property | Type | Description | Since |
|---|---|---|---|
name readonly | string | Entry name. | v0.0.0-alpha.2 |
entryType readonly | string | Entry category (for example "mark" or "measure"). | v0.0.0-alpha.2 |
startTime readonly | number | High-resolution start time in milliseconds. | v0.0.0-alpha.2 |
duration readonly | number | Elapsed duration in milliseconds. | v0.0.0-alpha.2 |
detail readonly optional | unknown | Optional user-supplied detail payload. | v0.0.0-alpha.2 |
PerformanceEntry.toJSON
Section titled “PerformanceEntry.toJSON”toJSON(): {
name: string;
entryType: string;
startTime: number;
duration: number;
detail?: unknown;
};
Return a plain JSON-serializable representation of this entry.
{
name: string;
entryType: string;
startTime: number;
duration: number;
detail?: unknown;
} — Entry summary object.PerformanceMark
Section titled “PerformanceMark”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(name: string, options?: PerformanceMarkOptions);
Construct a PerformanceMark.
| Name | Type | Description |
|---|---|---|
name | string | Mark identifier. |
options optional | PerformanceMarkOptions | Optional mark timestamp and detail payload. |
| Property | Type | Description | Since |
|---|---|---|---|
entryType readonly | "mark" | Always "mark". | v0.0.0-alpha.2 |
duration readonly | 0 | Always 0. | v0.0.0-alpha.2 |
PerformanceMeasure
Section titled “PerformanceMeasure”export class PerformanceMeasure extends PerformanceEntry {
override readonly entryType: "measure";
}
Performance timeline duration measurement created by performance.measure().
| Property | Type | Description | Since |
|---|---|---|---|
entryType readonly | "measure" | Always "measure". | v0.0.0-alpha.2 |
PerformanceObserver
Section titled “PerformanceObserver”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(callback: PerformanceObserverCallback);
Construct a PerformanceObserver.
| Name | Type | Description |
|---|---|---|
callback | PerformanceObserverCallback | Callback invoked with matching performance entries. |
| Property | Type | Description | Since |
|---|---|---|---|
supportedEntryTypes static readonly | readonly string[] | List of entry types supported by this runtime. | v0.0.0-alpha.2 |
PerformanceObserver.observe
Section titled “PerformanceObserver.observe”observe(options: PerformanceObserverObserveOptions): void;
Begin observing entries matching options.
| Name | Type | Description |
|---|---|---|
options | PerformanceObserverObserveOptions | Entry type filter and buffering configuration. |
voidPerformanceObserver.disconnect
Section titled “PerformanceObserver.disconnect”disconnect(): void;
Stop receiving performance entry notifications.
voidPerformanceObserver.takeRecords
Section titled “PerformanceObserver.takeRecords”takeRecords(): PerformanceEntry[];
Drain and return any queued entries not yet delivered to the callback.
PerformanceEntry[] — Array of buffered PerformanceEntry items.Interfaces
Section titled “Interfaces”PerformanceMarkOptions
Section titled “PerformanceMarkOptions”export interface PerformanceMarkOptions {
detail?: unknown;
startTime?: number;
}
Options accepted by performance.mark() and new PerformanceMark().
| Property | Type | Description | Since |
|---|---|---|---|
detail optional | unknown | Arbitrary metadata attached to the mark entry. | v0.0.0-alpha.2 |
startTime optional | number | Custom high-resolution timestamp in milliseconds. | v0.0.0-alpha.2 |
PerformanceMeasureOptions
Section titled “PerformanceMeasureOptions”export interface PerformanceMeasureOptions {
detail?: unknown;
duration?: number;
end?: number | string;
start?: number | string;
}
Options accepted by performance.measure().
| Property | Type | Description | Since |
|---|---|---|---|
detail optional | unknown | Arbitrary metadata attached to the measure entry. | v0.0.0-alpha.2 |
duration optional | number | Explicit duration in milliseconds. | v0.0.0-alpha.2 |
end optional | number | string | End timestamp or mark name. | v0.0.0-alpha.2 |
start optional | number | string | Start timestamp or mark name. | v0.0.0-alpha.2 |
PerformanceObserverEntryList
Section titled “PerformanceObserverEntryList”export interface PerformanceObserverEntryList {
getEntries(): PerformanceEntry[];
getEntriesByName(name: string, type?: string): PerformanceEntry[];
getEntriesByType(type: string): PerformanceEntry[];
}
List of PerformanceEntry records delivered to a PerformanceObserver callback.
PerformanceObserverEntryList.getEntries
Section titled “PerformanceObserverEntryList.getEntries”getEntries(): PerformanceEntry[];
Return all observed entries in chronological order.
PerformanceObserverEntryList.getEntriesByName
Section titled “PerformanceObserverEntryList.getEntriesByName”getEntriesByName(name: string, type?: string): PerformanceEntry[];
Return observed entries matching name and optional type.
| Name | Type | Description |
|---|---|---|
name | string | — |
type optional | string | — |
PerformanceObserverEntryList.getEntriesByType
Section titled “PerformanceObserverEntryList.getEntriesByType”getEntriesByType(type: string): PerformanceEntry[];
Return observed entries matching type.
| Name | Type | Description |
|---|---|---|
type | string | — |
PerformanceObserverObserveOptions
Section titled “PerformanceObserverObserveOptions”export interface PerformanceObserverObserveOptions {
entryTypes?: string[];
type?: string;
buffered?: boolean;
}
Subscription options accepted by PerformanceObserver.observe().
| Property | Type | Description | Since |
|---|---|---|---|
entryTypes optional | string[] | Array of entry types to observe. | v0.0.0-alpha.2 |
type optional | string | Single entry type to observe. | v0.0.0-alpha.2 |
buffered optional | boolean | Deliver previously buffered entries immediately when true. | v0.0.0-alpha.2 |
PerformanceConstants
Section titled “PerformanceConstants”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.
| Property | Type | Description | Since |
|---|---|---|---|
NODE_PERFORMANCE_GC_MAJOR readonly | number | Major GC kind constant. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_MINOR readonly | number | Minor (scavenge) GC kind constant. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_INCREMENTAL readonly | number | Incremental GC kind constant. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_WEAKCB readonly | number | Weak-callback GC kind constant. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_FLAGS_NO readonly | number | No GC flags constant. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED readonly | number | Retained-memory construct GC flag. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_FLAGS_FORCED readonly | number | Forced GC flag. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING readonly | number | Synchronous phantom processing GC flag. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE readonly | number | All-available-garbage GC flag. | v0.0.0-alpha.2 |
NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY readonly | number | All-external-memory GC flag. | v0.0.0-alpha.2 |
Performance
Section titled “Performance”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.
| Property | Type | Description | Since |
|---|---|---|---|
timeOrigin readonly | number | High-resolution Unix epoch origin timestamp in milliseconds. | v0.0.0-alpha.2 |
Performance.now
Section titled “Performance.now”now(): number;
Return current high-resolution monotonic timestamp in milliseconds.
numberPerformance.mark
Section titled “Performance.mark”mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
Record a named timestamp mark in the performance timeline.
| Name | Type | Description |
|---|---|---|
name | string | — |
options optional | PerformanceMarkOptions | — |
Performance.measure
Section titled “Performance.measure”measure(
name: string,
startOrMeasureOptions?: string | PerformanceMeasureOptions,
endMark?: string,
): PerformanceMeasure;
Record a duration measurement between marks or timestamps.
| Name | Type | Description |
|---|---|---|
name | string | — |
startOrMeasureOptions optional | string | PerformanceMeasureOptions | — |
endMark optional | string | — |
Performance.clearMarks
Section titled “Performance.clearMarks”clearMarks(name?: string): void;
Remove named mark(s) or all marks from the timeline.
| Name | Type | Description |
|---|---|---|
name optional | string | — |
voidPerformance.clearMeasures
Section titled “Performance.clearMeasures”clearMeasures(name?: string): void;
Remove named measure(s) or all measures from the timeline.
| Name | Type | Description |
|---|---|---|
name optional | string | — |
voidPerformance.getEntries
Section titled “Performance.getEntries”getEntries(): PerformanceEntry[];
Return all recorded entries in chronological order.
Performance.getEntriesByName
Section titled “Performance.getEntriesByName”getEntriesByName(name: string, type?: string): PerformanceEntry[];
Return recorded entries matching name and optional type.
| Name | Type | Description |
|---|---|---|
name | string | — |
type optional | string | — |
Performance.getEntriesByType
Section titled “Performance.getEntriesByType”getEntriesByType(type: string): PerformanceEntry[];
Return recorded entries matching type.
| Name | Type | Description |
|---|---|---|
type | string | — |
Performance.toJSON
Section titled “Performance.toJSON”toJSON(): { timeOrigin: number };
Return a JSON representation containing timeOrigin.
{ timeOrigin: number }EventLoopDelayMonitorOptions
Section titled “EventLoopDelayMonitorOptions”export interface EventLoopDelayMonitorOptions {
resolution?: number;
}
Options accepted by monitorEventLoopDelay().
| Property | Type | Description | Since |
|---|---|---|---|
resolution optional | number | Sampling resolution in milliseconds (default 10). | v0.0.0-alpha.2 |
IntervalHistogram
Section titled “IntervalHistogram”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.
| Property | Type | Description | Since |
|---|---|---|---|
min readonly | number | Minimum observed delay in nanoseconds. | v0.0.0-alpha.2 |
max readonly | number | Maximum observed delay in nanoseconds. | v0.0.0-alpha.2 |
mean readonly | number | Arithmetic mean delay in nanoseconds. | v0.0.0-alpha.2 |
stddev readonly | number | Standard deviation of delay samples in nanoseconds. | v0.0.0-alpha.2 |
count readonly | number | Total number of recorded samples. | v0.0.0-alpha.2 |
exceeds readonly | number | Number of times the event-loop delay exceeded the histogram maximum. | v0.0.0-alpha.2 |
percentiles readonly | Map<number, number> | Map of recorded percentile buckets to nanosecond values. | v0.0.0-alpha.2 |
IntervalHistogram.enable
Section titled “IntervalHistogram.enable”enable(): boolean;
Start collecting event-loop delay samples.
booleanIntervalHistogram.disable
Section titled “IntervalHistogram.disable”disable(): boolean;
Stop collecting event-loop delay samples.
booleanIntervalHistogram.reset
Section titled “IntervalHistogram.reset”reset(): void;
Reset all collected histogram statistics.
voidIntervalHistogram.percentile
Section titled “IntervalHistogram.percentile”percentile(percentile: number): number;
Return the delay value at the given percentile (0 < percentile <= 100).
| Name | Type | Description |
|---|---|---|
percentile | number | — |
numberType Aliases
Section titled “Type Aliases”PerformanceObserverCallback
Section titled “PerformanceObserverCallback”export type PerformanceObserverCallback = (
list: PerformanceObserverEntryList,
observer: PerformanceObserver,
) => void;
Callback invoked by a PerformanceObserver when new entries are recorded.
Constants
Section titled “Constants”constants
Section titled “constants”export const constants: PerformanceConstants;
Performance GC and entry-type constants.
performance
Section titled “performance”export const performance: Performance;
High-resolution performance measurement API.
Default Export
Section titled “Default Export”default export
Section titled “default export”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;
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.
