- Assertion testing
- Asynchronous context tracking
- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Corepack
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
Node.js v18.12.1 documentation
- Node.js v18.12.1
-
►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)performance.measure(name[, startMarkOrOptions[, endMark]])performance.nodeTimingperformance.now()performance.setResourceTimingBufferSize(maxSize)performance.timeOriginperformance.timerify(fn[, options])performance.toJSON()
- Class:
PerformanceEntryperformanceEntry.detailperformanceEntry.durationperformanceEntry.entryTypeperformanceEntry.flagsperformanceEntry.nameperformanceEntry.kindperformanceEntry.startTime- Garbage Collection ('gc') Details
- HTTP ('http') Details
- HTTP/2 ('http2') Details
- Timerify ('function') Details
- Net ('net') Details
- DNS ('dns') Details
- Class:
PerformanceNodeTiming - Class:
PerformanceResourceTimingperformanceResourceTiming.workerStartperformanceResourceTiming.redirectStartperformanceResourceTiming.redirectEndperformanceResourceTiming.fetchStartperformanceResourceTiming.domainLookupStartperformanceResourceTiming.domainLookupEndperformanceResourceTiming.connectStartperformanceResourceTiming.connectEndperformanceResourceTiming.secureConnectionStartperformanceResourceTiming.requestStartperformanceResourceTiming.responseEndperformanceResourceTiming.transferSizeperformanceResourceTiming.encodedBodySizeperformanceResourceTiming.decodedBodySizeperformanceResourceTiming.toJSON()
- Class:
perf_hooks.PerformanceObserver - Class:
PerformanceObserverEntryList perf_hooks.createHistogram([options])perf_hooks.monitorEventLoopDelay([options])- Class:
Histogramhistogram.counthistogram.countBigInthistogram.exceedshistogram.exceedsBigInthistogram.maxhistogram.maxBigInthistogram.meanhistogram.minhistogram.minBigInthistogram.percentile(percentile)histogram.percentileBigInt(percentile)histogram.percentileshistogram.percentilesBigInthistogram.reset()histogram.stddev
- Class:
IntervalHistogram extends Histogram - Class:
RecordableHistogram extends Histogram - Examples
Measuring the duration of async operations测量异步操作的持续时间Measuring how long it takes to load dependencies测量加载依赖项所需的时间Measuring how long one HTTP round-trip takes测量一次HTTP往返所需的时间Measuring how long the测量连接成功时网络连接(仅适用于TCP)所需的时间net.connect(only for TCP) takes when the connection is successfulMeasuring how long the DNS takes when the request is successful测量请求成功时DNS所需的时间
- Performance measurement APIs
-
►Index
- Assertion testing
Asynchronous context tracking异步上下文跟踪- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Corepack
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
- ►Other versions
- ►Options
Table of contents
Performance measurement APIs性能度量APIperf_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)performance.measure(name[, startMarkOrOptions[, endMark]])performance.nodeTimingperformance.now()performance.setResourceTimingBufferSize(maxSize)performance.timeOriginperformance.timerify(fn[, options])performance.toJSON()
- Class:
PerformanceEntryperformanceEntry.detailperformanceEntry.durationperformanceEntry.entryTypeperformanceEntry.flagsperformanceEntry.nameperformanceEntry.kindperformanceEntry.startTime- Garbage Collection ('gc') Details
- HTTP ('http') Details
- HTTP/2 ('http2') Details
- Timerify ('function') Details
- Net ('net') Details
- DNS ('dns') Details
- Class:
PerformanceNodeTiming - Class:
PerformanceResourceTimingperformanceResourceTiming.workerStartperformanceResourceTiming.redirectStartperformanceResourceTiming.redirectEndperformanceResourceTiming.fetchStartperformanceResourceTiming.domainLookupStartperformanceResourceTiming.domainLookupEndperformanceResourceTiming.connectStartperformanceResourceTiming.connectEndperformanceResourceTiming.secureConnectionStartperformanceResourceTiming.requestStartperformanceResourceTiming.responseEndperformanceResourceTiming.transferSizeperformanceResourceTiming.encodedBodySizeperformanceResourceTiming.decodedBodySizeperformanceResourceTiming.toJSON()
- Class:
perf_hooks.PerformanceObserver - Class:
PerformanceObserverEntryList perf_hooks.createHistogram([options])perf_hooks.monitorEventLoopDelay([options])- Class:
Histogramhistogram.counthistogram.countBigInthistogram.exceedshistogram.exceedsBigInthistogram.maxhistogram.maxBigInthistogram.meanhistogram.minhistogram.minBigInthistogram.percentile(percentile)histogram.percentileBigInt(percentile)histogram.percentileshistogram.percentilesBigInthistogram.reset()histogram.stddev
- Class:
IntervalHistogram extends Histogram - Class:
RecordableHistogram extends Histogram - Examples
Measuring the duration of async operations测量异步操作的持续时间Measuring how long it takes to load dependencies测量加载依赖项所需的时间Measuring how long one HTTP round-trip takes测量一次HTTP往返所需的时间Measuring how long the测量连接成功时net.connect(only for TCP) takes when the connection is successfulnet.connect(仅适用于TCP)所需的时间Measuring how long the DNS takes when the request is successful测量请求成功时DNS所需的时间
Performance measurement APIs性能度量API#
Stability: 2 - Stable
Source Code: lib/perf_hooks.js
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.该模块提供了W3C Web性能API的一个子集的实现,以及用于Node.js特定性能度量的其他API。
Node.js supports the following Web Performance APIs:Node.js支持以下Web性能API:
const { PerformanceObserver, performance } = require('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');
});