Node.js v26.9.0 documentation
- Node.js v26.9.0
- Table of contents
- Performance measurement APIs
perf_hooks.performanceperformance.clearMarks([name])performance.clearMeasures([name])performance.clearResourceTimings([name])performance.eventLoopUtilization([utilization1[, utilization2]])performance.getEntries()performance.getEntriesByName(name[, type])performance.getEntriesByType(type)performance.mark(name[, options])performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode, bodyInfo, responseStatus[, deliveryType])performance.measure(name[, startMarkOrOptions[, endMark]])performance.nodeTimingperformance.now()performance.setResourceTimingBufferSize(maxSize)performance.timeOriginperformance.timerify(fn[, options])performance.toJSON()
- Class:
PerformanceEntry - Class:
PerformanceMark - Class:
PerformanceMeasure - Class:
PerformanceNodeEntry - Class:
PerformanceNodeTiming - Class:
PerformanceResourceTimingperformanceResourceTiming.workerStartperformanceResourceTiming.redirectStartperformanceResourceTiming.redirectEndperformanceResourceTiming.fetchStartperformanceResourceTiming.domainLookupStartperformanceResourceTiming.domainLookupEndperformanceResourceTiming.connectStartperformanceResourceTiming.connectEndperformanceResourceTiming.secureConnectionStartperformanceResourceTiming.requestStartperformanceResourceTiming.finalResponseHeadersStartperformanceResourceTiming.firstInterimResponseStartperformanceResourceTiming.responseStartperformanceResourceTiming.responseEndperformanceResourceTiming.transferSizeperformanceResourceTiming.encodedBodySizeperformanceResourceTiming.decodedBodySizeperformanceResourceTiming.renderBlockingStatusperformanceResourceTiming.contentTypeperformanceResourceTiming.contentEncodingperformanceResourceTiming.toJSON()
- Class:
PerformanceObserver - Class:
PerformanceObserverEntryList perf_hooks.createHistogram([options])perf_hooks.importHistogram(data)perf_hooks.eventLoopUtilization([utilization1[, utilization2]])perf_hooks.monitorEventLoopDelay([options])perf_hooks.timerify(fn[, options])- Class:
Histogramhistogram.burnRate(sloTarget)histogram.counthistogram.countBigInthistogram.ccdf(value)histogram.cdf(value)histogram.cliffsD(other)histogram.cohensD(other)histogram.countAt(value)histogram.exceedshistogram.exceedsBigInthistogram.export()histogram.ewmaMeanhistogram.ewmaStddevhistogram.ewmaErrorRatehistogram.ksTest(other)histogram.kurtosishistogram.linearBuckets(stepSize)histogram.logBuckets(firstBucket, base)histogram.mannWhitneyTest(other)histogram.maxhistogram.maxBigInthistogram.meanhistogram.meanCI([options])histogram.minhistogram.minBigInthistogram.percentile(percentile)histogram.percentileBigInt(percentile)histogram.percentileCI(percentile[, options])histogram.percentileshistogram.percentilesBigInthistogram.percentilesAt(percentiles)histogram.reset()histogram.skewnesshistogram.stddevhistogram.welchTest(other[, options])
- Class:
ELDHistogram extends Histogram - Class:
RecordableHistogram extends Histogram - Histogram analysis examples
- Examples
- Performance measurement APIs
- Index
- About this documentation
- Usage and example
- Assertion testing
- Asynchronous context tracking
- Async hooks
- Benchmark runner
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Environment Variables
- Errors
- Events
- File system
- FFI
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Iterable Streams API
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Modules: TypeScript
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Single executable applications
- SQLite
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- Virtual File System
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
- Other versions
- Options
Performance measurement APIs#
Stability: 2 - Stable
This module provides an implementation of a subset of the W3C Web Performance APIs as well as additional APIs for Node.js-specific performance measurements.
Node.js supports the following Web Performance APIs:
import { performance, PerformanceObserver } from 'node:perf_hooks'; const obs = new PerformanceObserver((items) => { console.log(items.getEntries()[0].duration); performance.clearMarks(); }); obs.observe({ type: 'measure' }); performance.measure('Start to Now'); performance.mark('A'); doSomeLongRunningProcess(() => { performance.measure('A to Now', 'A'); performance.mark('B'); performance.measure('A to B', 'A', 'B'); });const { PerformanceObserver, performance } = require('node:perf_hooks'); const obs = new PerformanceObserver((items) => { console.log(items.getEntries()[0].duration); }); obs.observe({ type: 'measure' }); performance.measure('Start to Now'); performance.mark('A'); (async function doSomeLongRunningProcess() { await new Promise((r) => setTimeout(r, 5000)); performance.measure('A to Now', 'A'); performance.mark('B'); performance.measure('A to B', 'A', 'B'); })();
perf_hooks.performance#
An object that can be used to collect performance metrics from the current
Node.js instance. It is similar to window.performance in browsers.
performance.clearMarks([name])#
name<string>
If name is not provided, removes all PerformanceMark objects from the
Performance Timeline. If name is provided, removes only the named mark.
performance.clearMeasures([name])#
name<string>
If name is not provided, removes all PerformanceMeasure objects from the
Performance Timeline. If name is provided, removes only the named measure.
performance.clearResourceTimings([name])#
name<string>
If name is not provided, removes all PerformanceResourceTiming objects from
the Resource Timeline. If name is provided, removes only the named resource.
performance.eventLoopUtilization([utilization1[, utilization2]])#
utilization1<Object>The result of a previous call toeventLoopUtilization().utilization2<Object>The result of a previous call toeventLoopUtilization()prior toutilization1.- Returns:
<Object>
This is an alias of perf_hooks.eventLoopUtilization().
This property is an extension by Node.js. It is not available in Web browsers.
performance.getEntries()#
- Returns:
<PerformanceEntry>[]
Returns a list of PerformanceEntry objects in chronological order with
respect to performanceEntry.startTime. If you are only interested in
performance entries of certain types or that have certain names, see
performance.getEntriesByType() and performance.getEntriesByName().
performance.getEntriesByName(name[, type])#
name<string>type<string>- Returns:
<PerformanceEntry>[]
Returns a list of PerformanceEntry objects in chronological order
with respect to performanceEntry.startTime whose performanceEntry.name is
equal to name, and optionally, whose performanceEntry.entryType is equal to
type.
performance.getEntriesByType(type)#
type<string>- Returns:
<PerformanceEntry>[]
Returns a list of PerformanceEntry objects in chronological order
with respect to performanceEntry.startTime whose performanceEntry.entryType
is equal to type.
performance.mark(name[, options])#
Creates a new PerformanceMark entry in the Performance Timeline. A
PerformanceMark is a subclass of PerformanceEntry whose
performanceEntry.entryType is always 'mark', and whose
performanceEntry.duration is always 0. Performance marks are used
to mark specific significant moments in the Performance Timeline.
The created PerformanceMark entry is put in the global Performance Timeline
and can be queried with performance.getEntries,
performance.getEntriesByName, and performance.getEntriesByType. When the
observation is performed, the entries should be cleared from the global
Performance Timeline manually with performance.clearMarks.
performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode, bodyInfo, responseStatus[, deliveryType])#
timingInfo<Object>Fetch Timing InforequestedUrl<string>The resource urlinitiatorType<string>The initiator name, e.g: 'fetch'global<Object>cacheMode<string>The cache mode must be an empty string ('') or 'local'bodyInfo<Object>Fetch Response Body InforesponseStatus<number>The response's status codedeliveryType<string>The delivery type. Default:''.
This property is an extension by Node.js. It is not available in Web browsers.
Creates a new PerformanceResourceTiming entry in the Resource Timeline. A
PerformanceResourceTiming is a subclass of PerformanceEntry whose
performanceEntry.entryType is always 'resource'. Performance resources
are used to mark moments in the Resource Timeline.
The created PerformanceMark entry is put in the global Resource Timeline
and can be queried with performance.getEntries,
performance.getEntriesByName, and performance.getEntriesByType. When the
observation is performed, the entries should be cleared from the global
Performance Timeline manually with performance.clearResourceTimings.
performance.measure(name[, startMarkOrOptions[, endMark]])#
name<string>startMarkOrOptions<string>|<Object>Optional.detail<any>Additional optional detail to include with the measure.duration<number>Duration between start and end times.end<number>|<string>Timestamp to be used as the end time, or a string identifying a previously recorded mark.start<number>|<string>Timestamp to be used as the start time, or a string identifying a previously recorded mark.
endMark<string>Optional. Must be omitted ifstartMarkOrOptionsis an<Object>.
Creates a new PerformanceMeasure entry in the Performance Timeline. A
PerformanceMeasure is a subclass of PerformanceEntry whose
performanceEntry.entryType is always 'measure', and whose
performanceEntry.duration measures the number of milliseconds elapsed since
startMark and endMark.
The startMark argument may identify any existing PerformanceMark in the
Performance Timeline, or may identify any of the timestamp properties
provided by the PerformanceNodeTiming class. If the named startMark does
not exist, an error is thrown.
The optional endMark argument must identify any existing PerformanceMark
in the Performance Timeline or any of the timestamp properties provided by the
PerformanceNodeTiming class. endMark will be performance.now()
if no parameter is passed, otherwise if the named endMark does not exist, an
error will be thrown.
The created PerformanceMeasure entry is put in the global Performance Timeline
and can be queried with performance.getEntries,
performance.getEntriesByName, and performance.getEntriesByType. When the
observation is performed, the entries should be cleared from the global
Performance Timeline manually with performance.clearMeasures.
performance.nodeTiming#
- Type:
<PerformanceNodeTiming>
This property is an extension by Node.js. It is not available in Web browsers.
An instance of the PerformanceNodeTiming class that provides performance
metrics for specific Node.js operational milestones.
performance.now()#
- Returns:
<number>
Returns the current high resolution millisecond timestamp, where 0 represents
the start of the current node process.
performance.setResourceTimingBufferSize(maxSize)#
Sets the global performance resource timing buffer size to the specified number of "resource" type performance entry objects.
By default the max buffer size is set to 250.
performance.timeOrigin#
- Type:
<number>
The timeOrigin specifies the high resolution millisecond timestamp at
which the current node process began, measured in Unix time.
performance.timerify(fn[, options])#
fn<Function>options<Object>histogram<RecordableHistogram>A histogram object created usingperf_hooks.createHistogram()that will record runtime durations in nanoseconds.
This is an alias of perf_hooks.timerify().
This property is an extension by Node.js. It is not available in Web browsers.
performance.toJSON()#
An object which is JSON representation of the performance object. It
is similar to window.performance.toJSON in browsers.
Event: 'resourcetimingbufferfull'#
The 'resourcetimingbufferfull' event is fired when the global performance
resource timing buffer is full. Adjust resource timing buffer size with
performance.setResourceTimingBufferSize() or clear the buffer with
performance.clearResourceTimings() in the event listener to allow
more entries to be added to the performance timeline buffer.
Class: PerformanceEntry#
The constructor of this class is not exposed to users directly.
performanceEntry.duration#
- Type:
<number>
The total number of milliseconds elapsed for this entry. This value will not be meaningful for all Performance Entry types.
performanceEntry.entryType#
- Type:
<string>
The type of the performance entry. It may be one of:
'dns'(Node.js only)'function'(Node.js only)'gc'(Node.js only)'http2'(Node.js only)'http'(Node.js only)'mark'(available on the Web)'measure'(available on the Web)'net'(Node.js only)'node'(Node.js only)'resource'(available on the Web)
performanceEntry.name#
- Type:
<string>
The name of the performance entry.
performanceEntry.startTime#
- Type:
<number>
The high resolution millisecond timestamp marking the starting time of the Performance Entry.
Class: PerformanceMark#
- Extends:
<PerformanceEntry>
Exposes marks created via the Performance.mark() method.
performanceMark.detail#
- Type:
<any>
Additional detail specified when creating with Performance.mark() method.
Class: PerformanceMeasure#
- Extends:
<PerformanceEntry>
Exposes measures created via the Performance.measure() method.
The constructor of this class is not exposed to users directly.
performanceMeasure.detail#
- Type:
<any>
Additional detail specified when creating with Performance.measure() method.
Class: PerformanceNodeEntry#
- Extends:
<PerformanceEntry>
This class is an extension by Node.js. It is not available in Web browsers.
Provides detailed Node.js timing data.
The constructor of this class is not exposed to users directly.
performanceNodeEntry.detail#
- Type:
<any>
Additional detail specific to the entryType.
performanceNodeEntry.flags#
Stability: 0 - Deprecated: Use performanceNodeEntry.detail instead.
- Type:
<number>
When performanceEntry.entryType is equal to 'gc', the performance.flags
property contains additional information about garbage collection operation.
The value may be one of:
perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NOperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINEDperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCEDperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSINGperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGEperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORYperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE
performanceNodeEntry.kind#
Stability: 0 - Deprecated: Use performanceNodeEntry.detail instead.
- Type:
<number>
When performanceEntry.entryType is equal to 'gc', the performance.kind
property identifies the type of garbage collection operation that occurred.
The value may be one of:
perf_hooks.constants.NODE_PERFORMANCE_GC_MAJORperf_hooks.constants.NODE_PERFORMANCE_GC_MINORperf_hooks.constants.NODE_PERFORMANCE_GC_MINOR_MARK_SWEEPperf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTALperf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB
Garbage Collection ('gc') Details#
When performanceEntry.type is equal to 'gc', the
performanceNodeEntry.detail property will be an <Object> with two properties:
kind<number>One of:perf_hooks.constants.NODE_PERFORMANCE_GC_MAJORperf_hooks.constants.NODE_PERFORMANCE_GC_MINORperf_hooks.constants.NODE_PERFORMANCE_GC_MINOR_MARK_SWEEPperf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTALperf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB
flags<number>One of:perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NOperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINEDperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCEDperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSINGperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGEperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORYperf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE
HTTP ('http') Details#
When performanceEntry.type is equal to 'http', the
performanceNodeEntry.detail property will be an <Object> containing
additional information.
If performanceEntry.name is equal to HttpClient, the detail
will contain the following properties: req, res. And the req property
will be an <Object> containing method, url, headers, the res property
will be an <Object> containing statusCode, statusMessage, headers.
If performanceEntry.name is equal to HttpRequest, the detail
will contain the following properties: req, res. And the req property
will be an <Object> containing method, url, headers, the res property
will be an <Object> containing statusCode, statusMessage, headers.
This could add additional memory overhead and should only be used for diagnostic purposes, not left turned on in production by default.
HTTP/2 ('http2') Details#
When performanceEntry.type is equal to 'http2', the
performanceNodeEntry.detail property will be an <Object> containing
additional performance information.
If performanceEntry.name is equal to Http2Stream, the detail
will contain the following properties:
bytesRead<number>The number ofDATAframe bytes received for thisHttp2Stream.bytesWritten<number>The number ofDATAframe bytes sent for thisHttp2Stream.id<number>The identifier of the associatedHttp2StreamtimeToFirstByte<number>The number of milliseconds elapsed between thePerformanceEntrystartTimeand the reception of the firstDATAframe.timeToFirstByteSent<number>The number of milliseconds elapsed between thePerformanceEntrystartTimeand sending of the firstDATAframe.timeToFirstHeader<number>The number of milliseconds elapsed between thePerformanceEntrystartTimeand the reception of the first header.
If performanceEntry.name is equal to Http2Session, the detail will
contain the following properties:
bytesRead<number>The number of bytes received for thisHttp2Session.bytesWritten<number>The number of bytes sent for thisHttp2Session.framesReceived<number>The number of HTTP/2 frames received by theHttp2Session.framesSent<number>The number of HTTP/2 frames sent by theHttp2Session.maxConcurrentStreams<number>The maximum number of streams concurrently open during the lifetime of theHttp2Session.pingRTT<number>The number of milliseconds elapsed since the transmission of aPINGframe and the reception of its acknowledgment. Only present if aPINGframe has been sent on theHttp2Session.streamAverageDuration<number>The average duration (in milliseconds) for allHttp2Streaminstances.streamCount<number>The number ofHttp2Streaminstances processed by theHttp2Session.type<string>Either'server'or'client'to identify the type ofHttp2Session.
Timerify ('function') Details#
When performanceEntry.type is equal to 'function', the
performanceNodeEntry.detail property will be an <Array> listing
the input arguments to the timed function.
Net ('net') Details#
When performanceEntry.type is equal to 'net', the
performanceNodeEntry.detail property will be an <Object> containing
additional information.
If performanceEntry.name is equal to connect, the detail
will contain the following properties: host, port.
DNS ('dns') Details#
When performanceEntry.type is equal to 'dns', the
performanceNodeEntry.detail property will be an <Object> containing
additional information.
If performanceEntry.name is equal to lookup, the detail
will contain the following properties: hostname, family, hints, verbatim,
addresses.
If performanceEntry.name is equal to lookupService, the detail will
contain the following properties: host, port, hostname, service.
If performanceEntry.name is equal to queryxxx or getHostByAddr, the detail will
contain the following properties: host, ttl, result. The value of result is
same as the result of queryxxx or getHostByAddr.
Class: PerformanceNodeTiming#
- Extends:
<PerformanceEntry>
This property is an extension by Node.js. It is not available in Web browsers.
Provides timing details for Node.js itself. The constructor of this class is not exposed to users.
performanceNodeTiming.bootstrapComplete#
- Type:
<number>
The high resolution millisecond timestamp at which the Node.js process completed bootstrapping. If bootstrapping has not yet finished, the property has the value of -1.
performanceNodeTiming.environment#
- Type:
<number>
The high resolution millisecond timestamp at which the Node.js environment was initialized.
performanceNodeTiming.idleTime#
- Type:
<number>
The high resolution millisecond timestamp of the amount of time the event loop
has been idle within the event loop's event provider (e.g. epoll_wait). This
does not take CPU usage into consideration. If the event loop has not yet
started (e.g., in the first tick of the main script), the property has the
value of 0.
performanceNodeTiming.loopExit#
- Type:
<number>
The high resolution millisecond timestamp at which the Node.js event loop
exited. If the event loop has not yet exited, the property has the value of -1.
It can only have a value of not -1 in a handler of the 'exit' event.
performanceNodeTiming.loopStart#
- Type:
<number>
The high resolution millisecond timestamp at which the Node.js event loop started. If the event loop has not yet started (e.g., in the first tick of the main script), the property has the value of -1.
performanceNodeTiming.nodeStart#
- Type:
<number>
The high resolution millisecond timestamp at which the Node.js process was initialized.
performanceNodeTiming.uvMetricsInfo#
- Returns:
<Object>
This is a wrapper to the uv_metrics_info function.
It returns the current set of event loop metrics.
It is recommended to use this property inside a function whose execution was
scheduled using setImmediate to avoid collecting metrics before finishing all
operations scheduled during the current loop iteration.
const { performance } = require('node:perf_hooks'); setImmediate(() => { console.log(performance.nodeTiming.uvMetricsInfo); });import { performance } from 'node:perf_hooks'; setImmediate(() => { console.log(performance.nodeTiming.uvMetricsInfo); });
performanceNodeTiming.v8Start#
- Type:
<number>
The high resolution millisecond timestamp at which the V8 platform was initialized.
Class: PerformanceResourceTiming#
- Extends:
<PerformanceEntry>
Provides detailed network timing data regarding the loading of an application's resources.
The constructor of this class is not exposed to users directly.
performanceResourceTiming.workerStart#
- Type:
<number>
The high resolution millisecond timestamp at immediately before dispatching
the fetch request. If the resource is not intercepted by a worker the property
will always return 0.
performanceResourceTiming.redirectStart#
- Type:
<number>
The high resolution millisecond timestamp that represents the start time of the fetch which initiates the redirect.
performanceResourceTiming.redirectEnd#
- Type:
<number>
The high resolution millisecond timestamp that will be created immediately after receiving the last byte of the response of the last redirect.
performanceResourceTiming.fetchStart#
- Type:
<number>
The high resolution millisecond timestamp immediately before the Node.js starts to fetch the resource.
performanceResourceTiming.domainLookupStart#
- Type:
<number>
The high resolution millisecond timestamp immediately before the Node.js starts the domain name lookup for the resource.