1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width"> 6 <meta name="nodejs.org:node-version" content="v18.20.1"> 7 <title>Performance measurement APIs | Node.js v18.20.1 Documentation</title> 8 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback"> 9 <link rel="stylesheet" href="assets/style.css"> 10 <link rel="stylesheet" href="assets/hljs.css"> 11 <link rel="canonical" href="https://nodejs.org/api/perf_hooks.html"> 12 <script async defer src="assets/api.js" type="text/javascript"></script> 13 14</head> 15<body class="alt apidoc" id="api-section-perf_hooks"> 16 <div id="content" class="clearfix"> 17 <div id="column2" class="interior"> 18 <div id="intro" class="interior"> 19 <a href="/" title="Go back to the home page"> 20 Node.js 21 </a> 22 </div> 23 <ul> 24<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li> 25<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li> 26</ul> 27<hr class="line"> 28<ul> 29<li><a href="assert.html" class="nav-assert">Assertion testing</a></li> 30<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li> 31<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li> 32<li><a href="buffer.html" class="nav-buffer">Buffer</a></li> 33<li><a href="addons.html" class="nav-addons">C++ addons</a></li> 34<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li> 35<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li> 36<li><a href="child_process.html" class="nav-child_process">Child processes</a></li> 37<li><a href="cluster.html" class="nav-cluster">Cluster</a></li> 38<li><a href="cli.html" class="nav-cli">Command-line options</a></li> 39<li><a href="console.html" class="nav-console">Console</a></li> 40<li><a href="corepack.html" class="nav-corepack">Corepack</a></li> 41<li><a href="crypto.html" class="nav-crypto">Crypto</a></li> 42<li><a href="debugger.html" class="nav-debugger">Debugger</a></li> 43<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li> 44<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li> 45<li><a href="dns.html" class="nav-dns">DNS</a></li> 46<li><a href="domain.html" class="nav-domain">Domain</a></li> 47<li><a href="errors.html" class="nav-errors">Errors</a></li> 48<li><a href="events.html" class="nav-events">Events</a></li> 49<li><a href="fs.html" class="nav-fs">File system</a></li> 50<li><a href="globals.html" class="nav-globals">Globals</a></li> 51<li><a href="http.html" class="nav-http">HTTP</a></li> 52<li><a href="http2.html" class="nav-http2">HTTP/2</a></li> 53<li><a href="https.html" class="nav-https">HTTPS</a></li> 54<li><a href="inspector.html" class="nav-inspector">Inspector</a></li> 55<li><a href="intl.html" class="nav-intl">Internationalization</a></li> 56<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li> 57<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li> 58<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li> 59<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li> 60<li><a href="net.html" class="nav-net">Net</a></li> 61<li><a href="os.html" class="nav-os">OS</a></li> 62<li><a href="path.html" class="nav-path">Path</a></li> 63<li><a href="perf_hooks.html" class="nav-perf_hooks active">Performance hooks</a></li> 64<li><a href="permissions.html" class="nav-permissions">Permissions</a></li> 65<li><a href="process.html" class="nav-process">Process</a></li> 66<li><a href="punycode.html" class="nav-punycode">Punycode</a></li> 67<li><a href="querystring.html" class="nav-querystring">Query strings</a></li> 68<li><a href="readline.html" class="nav-readline">Readline</a></li> 69<li><a href="repl.html" class="nav-repl">REPL</a></li> 70<li><a href="report.html" class="nav-report">Report</a></li> 71<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li> 72<li><a href="stream.html" class="nav-stream">Stream</a></li> 73<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li> 74<li><a href="test.html" class="nav-test">Test runner</a></li> 75<li><a href="timers.html" class="nav-timers">Timers</a></li> 76<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li> 77<li><a href="tracing.html" class="nav-tracing">Trace events</a></li> 78<li><a href="tty.html" class="nav-tty">TTY</a></li> 79<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li> 80<li><a href="url.html" class="nav-url">URL</a></li> 81<li><a href="util.html" class="nav-util">Utilities</a></li> 82<li><a href="v8.html" class="nav-v8">V8</a></li> 83<li><a href="vm.html" class="nav-vm">VM</a></li> 84<li><a href="wasi.html" class="nav-wasi">WASI</a></li> 85<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li> 86<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li> 87<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li> 88<li><a href="zlib.html" class="nav-zlib">Zlib</a></li> 89</ul> 90<hr class="line"> 91<ul> 92<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li> 93</ul> 94 </div> 95 96 <div id="column1" data-id="perf_hooks" class="interior"> 97 <header class="header"> 98 <div class="header-container"> 99 <h1>Node.js v18.20.1 documentation</h1> 100 <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden> 101 <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24"> 102 <path fill="none" d="M0 0h24v24H0z" /> 103 <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/> 104 <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/> 105 </svg> 106 <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24"> 107 <path d="M0 0h24v24H0z" fill="none" /> 108 <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/> 109 </svg> 110 </button> 111 </div> 112 <div id="gtoc"> 113 <ul> 114 <li class="pinned-header">Node.js v18.20.1</li> 115 116 <li class="picker-header"> 117 <a href="#"> 118 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span> 119 Table of contents 120 </a> 121 122 <div class="picker"><div class="toc"><ul> 123<li><span class="stability_2"><a href="#performance-measurement-apis">Performance measurement APIs</a></span> 124<ul> 125<li><a href="#perf_hooksperformance"><code>perf_hooks.performance</code></a> 126<ul> 127<li><a href="#performanceclearmarksname"><code>performance.clearMarks([name])</code></a></li> 128<li><a href="#performanceclearmeasuresname"><code>performance.clearMeasures([name])</code></a></li> 129<li><a href="#performanceclearresourcetimingsname"><code>performance.clearResourceTimings([name])</code></a></li> 130<li><a href="#performanceeventlooputilizationutilization1-utilization2"><code>performance.eventLoopUtilization([utilization1[, utilization2]])</code></a></li> 131<li><a href="#performancegetentries"><code>performance.getEntries()</code></a></li> 132<li><a href="#performancegetentriesbynamename-type"><code>performance.getEntriesByName(name[, type])</code></a></li> 133<li><a href="#performancegetentriesbytypetype"><code>performance.getEntriesByType(type)</code></a></li> 134<li><a href="#performancemarkname-options"><code>performance.mark([name[, options]])</code></a></li> 135<li><a href="#performancemarkresourcetimingtiminginfo-requestedurl-initiatortype-global-cachemode"><code>performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode)</code></a></li> 136<li><a href="#performancemeasurename-startmarkoroptions-endmark"><code>performance.measure(name[, startMarkOrOptions[, endMark]])</code></a></li> 137<li><a href="#performancenodetiming"><code>performance.nodeTiming</code></a></li> 138<li><a href="#performancenow"><code>performance.now()</code></a></li> 139<li><a href="#performancesetresourcetimingbuffersizemaxsize"><code>performance.setResourceTimingBufferSize(maxSize)</code></a></li> 140<li><a href="#performancetimeorigin"><code>performance.timeOrigin</code></a></li> 141<li><a href="#performancetimerifyfn-options"><code>performance.timerify(fn[, options])</code></a></li> 142<li><a href="#performancetojson"><code>performance.toJSON()</code></a> 143<ul> 144<li><a href="#event-resourcetimingbufferfull">Event: <code>'resourcetimingbufferfull'</code></a></li> 145</ul> 146</li> 147</ul> 148</li> 149<li><a href="#class-performanceentry">Class: <code>PerformanceEntry</code></a> 150<ul> 151<li><a href="#performanceentrydetail"><code>performanceEntry.detail</code></a></li> 152<li><a href="#performanceentryduration"><code>performanceEntry.duration</code></a></li> 153<li><a href="#performanceentryentrytype"><code>performanceEntry.entryType</code></a></li> 154<li><a href="#performanceentryflags"><code>performanceEntry.flags</code></a></li> 155<li><a href="#performanceentryname"><code>performanceEntry.name</code></a></li> 156<li><a href="#performanceentrykind"><code>performanceEntry.kind</code></a></li> 157<li><a href="#performanceentrystarttime"><code>performanceEntry.startTime</code></a></li> 158<li><a href="#garbage-collection-gc-details">Garbage Collection ('gc') Details</a></li> 159<li><a href="#http-http-details">HTTP ('http') Details</a></li> 160<li><a href="#http2-http2-details">HTTP/2 ('http2') Details</a></li> 161<li><a href="#timerify-function-details">Timerify ('function') Details</a></li> 162<li><a href="#net-net-details">Net ('net') Details</a></li> 163<li><a href="#dns-dns-details">DNS ('dns') Details</a></li> 164</ul> 165</li> 166<li><a href="#class-performancenodetiming">Class: <code>PerformanceNodeTiming</code></a> 167<ul> 168<li><a href="#performancenodetimingbootstrapcomplete"><code>performanceNodeTiming.bootstrapComplete</code></a></li> 169<li><a href="#performancenodetimingenvironment"><code>performanceNodeTiming.environment</code></a></li> 170<li><a href="#performancenodetimingidletime"><code>performanceNodeTiming.idleTime</code></a></li> 171<li><a href="#performancenodetimingloopexit"><code>performanceNodeTiming.loopExit</code></a></li> 172<li><a href="#performancenodetimingloopstart"><code>performanceNodeTiming.loopStart</code></a></li> 173<li><a href="#performancenodetimingnodestart"><code>performanceNodeTiming.nodeStart</code></a></li> 174<li><a href="#performancenodetimingv8start"><code>performanceNodeTiming.v8Start</code></a></li> 175</ul> 176</li> 177<li><a href="#class-performanceresourcetiming">Class: <code>PerformanceResourceTiming</code></a> 178<ul> 179<li><a href="#performanceresourcetimingworkerstart"><code>performanceResourceTiming.workerStart</code></a></li> 180<li><a href="#performanceresourcetimingredirectstart"><code>performanceResourceTiming.redirectStart</code></a></li> 181<li><a href="#performanceresourcetimingredirectend"><code>performanceResourceTiming.redirectEnd</code></a></li> 182<li><a href="#performanceresourcetimingfetchstart"><code>performanceResourceTiming.fetchStart</code></a></li> 183<li><a href="#performanceresourcetimingdomainlookupstart"><code>performanceResourceTiming.domainLookupStart</code></a></li> 184<li><a href="#performanceresourcetimingdomainlookupend"><code>performanceResourceTiming.domainLookupEnd</code></a></li> 185<li><a href="#performanceresourcetimingconnectstart"><code>performanceResourceTiming.connectStart</code></a></li> 186<li><a href="#performanceresourcetimingconnectend"><code>performanceResourceTiming.connectEnd</code></a></li> 187<li><a href="#performanceresourcetimingsecureconnectionstart"><code>performanceResourceTiming.secureConnectionStart</code></a></li> 188<li><a href="#performanceresourcetimingrequeststart"><code>performanceResourceTiming.requestStart</code></a></li> 189<li><a href="#performanceresourcetimingresponseend"><code>performanceResourceTiming.responseEnd</code></a></li> 190<li><a href="#performanceresourcetimingtransfersize"><code>performanceResourceTiming.transferSize</code></a></li> 191<li><a href="#performanceresourcetimingencodedbodysize"><code>performanceResourceTiming.encodedBodySize</code></a></li> 192<li><a href="#performanceresourcetimingdecodedbodysize"><code>performanceResourceTiming.decodedBodySize</code></a></li> 193<li><a href="#performanceresourcetimingtojson"><code>performanceResourceTiming.toJSON()</code></a></li> 194</ul> 195</li> 196<li><a href="#class-perf_hooksperformanceobserver">Class: <code>perf_hooks.PerformanceObserver</code></a> 197<ul> 198<li><a href="#performanceobserversupportedentrytypes"><code>PerformanceObserver.supportedEntryTypes</code></a></li> 199<li><a href="#new-performanceobservercallback"><code>new PerformanceObserver(callback)</code></a></li> 200<li><a href="#performanceobserverdisconnect"><code>performanceObserver.disconnect()</code></a></li> 201<li><a href="#performanceobserverobserveoptions"><code>performanceObserver.observe(options)</code></a></li> 202</ul> 203</li> 204<li><a href="#class-performanceobserverentrylist">Class: <code>PerformanceObserverEntryList</code></a> 205<ul> 206<li><a href="#performanceobserverentrylistgetentries"><code>performanceObserverEntryList.getEntries()</code></a></li> 207<li><a href="#performanceobserverentrylistgetentriesbynamename-type"><code>performanceObserverEntryList.getEntriesByName(name[, type])</code></a></li> 208<li><a href="#performanceobserverentrylistgetentriesbytypetype"><code>performanceObserverEntryList.getEntriesByType(type)</code></a></li> 209</ul> 210</li> 211<li><a href="#perf_hookscreatehistogramoptions"><code>perf_hooks.createHistogram([options])</code></a></li> 212<li><a href="#perf_hooksmonitoreventloopdelayoptions"><code>perf_hooks.monitorEventLoopDelay([options])</code></a></li> 213<li><a href="#class-histogram">Class: <code>Histogram</code></a> 214<ul> 215<li><a href="#histogramcount"><code>histogram.count</code></a></li> 216<li><a href="#histogramcountbigint"><code>histogram.countBigInt</code></a></li> 217<li><a href="#histogramexceeds"><code>histogram.exceeds</code></a></li> 218<li><a href="#histogramexceedsbigint"><code>histogram.exceedsBigInt</code></a></li> 219<li><a href="#histogrammax"><code>histogram.max</code></a></li> 220<li><a href="#histogrammaxbigint"><code>histogram.maxBigInt</code></a></li> 221<li><a href="#histogrammean"><code>histogram.mean</code></a></li> 222<li><a href="#histogrammin"><code>histogram.min</code></a></li> 223<li><a href="#histogramminbigint"><code>histogram.minBigInt</code></a></li> 224<li><a href="#histogrampercentilepercentile"><code>histogram.percentile(percentile)</code></a></li> 225<li><a href="#histogrampercentilebigintpercentile"><code>histogram.percentileBigInt(percentile)</code></a></li> 226<li><a href="#histogrampercentiles"><code>histogram.percentiles</code></a></li> 227<li><a href="#histogrampercentilesbigint"><code>histogram.percentilesBigInt</code></a></li> 228<li><a href="#histogramreset"><code>histogram.reset()</code></a></li> 229<li><a href="#histogramstddev"><code>histogram.stddev</code></a></li> 230</ul> 231</li> 232<li><a href="#class-intervalhistogram-extends-histogram">Class: <code>IntervalHistogram extends Histogram</code></a> 233<ul> 234<li><a href="#histogramdisable"><code>histogram.disable()</code></a></li> 235<li><a href="#histogramenable"><code>histogram.enable()</code></a></li> 236<li><a href="#cloning-an-intervalhistogram">Cloning an <code>IntervalHistogram</code></a></li> 237</ul> 238</li> 239<li><a href="#class-recordablehistogram-extends-histogram">Class: <code>RecordableHistogram extends Histogram</code></a> 240<ul> 241<li><a href="#histogramaddother"><code>histogram.add(other)</code></a></li> 242<li><a href="#histogramrecordval"><code>histogram.record(val)</code></a></li> 243<li><a href="#histogramrecorddelta"><code>histogram.recordDelta()</code></a></li> 244</ul> 245</li> 246<li><a href="#examples">Examples</a> 247<ul> 248<li><a href="#measuring-the-duration-of-async-operations">Measuring the duration of async operations</a></li> 249<li><a href="#measuring-how-long-it-takes-to-load-dependencies">Measuring how long it takes to load dependencies</a></li> 250<li><a href="#measuring-how-long-one-http-round-trip-takes">Measuring how long one HTTP round-trip takes</a></li> 251<li><a href="#measuring-how-long-the-netconnect-only-for-tcp-takes-when-the-connection-is-successful">Measuring how long the <code>net.connect</code> (only for TCP) takes when the connection is successful</a></li> 252<li><a href="#measuring-how-long-the-dns-takes-when-the-request-is-successful">Measuring how long the DNS takes when the request is successful</a></li> 253</ul> 254</li> 255</ul> 256</li> 257</ul></div></div> 258 </li> 259 260 261 <li class="picker-header"> 262 <a href="#"> 263 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span> 264 Index 265 </a> 266 267 <div class="picker"><ul> 268<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li> 269<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li> 270 271 <li> 272 <a href="index.html">Index</a> 273 </li> 274 </ul> 275 276<hr class="line"> 277<ul> 278<li><a href="assert.html" class="nav-assert">Assertion testing</a></li> 279<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li> 280<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li> 281<li><a href="buffer.html" class="nav-buffer">Buffer</a></li> 282<li><a href="addons.html" class="nav-addons">C++ addons</a></li> 283<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li> 284<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li> 285<li><a href="child_process.html" class="nav-child_process">Child processes</a></li> 286<li><a href="cluster.html" class="nav-cluster">Cluster</a></li> 287<li><a href="cli.html" class="nav-cli">Command-line options</a></li> 288<li><a href="console.html" class="nav-console">Console</a></li> 289<li><a href="corepack.html" class="nav-corepack">Corepack</a></li> 290<li><a href="crypto.html" class="nav-crypto">Crypto</a></li> 291<li><a href="debugger.html" class="nav-debugger">Debugger</a></li> 292<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li> 293<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li> 294<li><a href="dns.html" class="nav-dns">DNS</a></li> 295<li><a href="domain.html" class="nav-domain">Domain</a></li> 296<li><a href="errors.html" class="nav-errors">Errors</a></li> 297<li><a href="events.html" class="nav-events">Events</a></li> 298<li><a href="fs.html" class="nav-fs">File system</a></li> 299<li><a href="globals.html" class="nav-globals">Globals</a></li> 300<li><a href="http.html" class="nav-http">HTTP</a></li> 301<li><a href="http2.html" class="nav-http2">HTTP/2</a></li> 302<li><a href="https.html" class="nav-https">HTTPS</a></li> 303<li><a href="inspector.html" class="nav-inspector">Inspector</a></li> 304<li><a href="intl.html" class="nav-intl">Internationalization</a></li> 305<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li> 306<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li> 307<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li> 308<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li> 309<li><a href="net.html" class="nav-net">Net</a></li> 310<li><a href="os.html" class="nav-os">OS</a></li> 311<li><a href="path.html" class="nav-path">Path</a></li> 312<li><a href="perf_hooks.html" class="nav-perf_hooks active">Performance hooks</a></li> 313<li><a href="permissions.html" class="nav-permissions">Permissions</a></li> 314<li><a href="process.html" class="nav-process">Process</a></li> 315<li><a href="punycode.html" class="nav-punycode">Punycode</a></li> 316<li><a href="querystring.html" class="nav-querystring">Query strings</a></li> 317<li><a href="readline.html" class="nav-readline">Readline</a></li> 318<li><a href="repl.html" class="nav-repl">REPL</a></li> 319<li><a href="report.html" class="nav-report">Report</a></li> 320<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li> 321<li><a href="stream.html" class="nav-stream">Stream</a></li> 322<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li> 323<li><a href="test.html" class="nav-test">Test runner</a></li> 324<li><a href="timers.html" class="nav-timers">Timers</a></li> 325<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li> 326<li><a href="tracing.html" class="nav-tracing">Trace events</a></li> 327<li><a href="tty.html" class="nav-tty">TTY</a></li> 328<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li> 329<li><a href="url.html" class="nav-url">URL</a></li> 330<li><a href="util.html" class="nav-util">Utilities</a></li> 331<li><a href="v8.html" class="nav-v8">V8</a></li> 332<li><a href="vm.html" class="nav-vm">VM</a></li> 333<li><a href="wasi.html" class="nav-wasi">WASI</a></li> 334<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li> 335<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li> 336<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li> 337<li><a href="zlib.html" class="nav-zlib">Zlib</a></li> 338</ul> 339<hr class="line"> 340<ul> 341<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li> 342</ul></div> 343 </li> 344 345 346 <li class="picker-header"> 347 <a href="#"> 348 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span> 349 Other versions 350 </a> 351 <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/perf_hooks.html">21.x</a></li> 352<li><a href="https://nodejs.org/docs/latest-v20.x/api/perf_hooks.html">20.x <b>LTS</b></a></li> 353<li><a href="https://nodejs.org/docs/latest-v19.x/api/perf_hooks.html">19.x</a></li> 354<li><a href="https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html">18.x <b>LTS</b></a></li> 355<li><a href="https://nodejs.org/docs/latest-v17.x/api/perf_hooks.html">17.x</a></li> 356<li><a href="https://nodejs.org/docs/latest-v16.x/api/perf_hooks.html">16.x</a></li> 357<li><a href="https://nodejs.org/docs/latest-v15.x/api/perf_hooks.html">15.x</a></li> 358<li><a href="https://nodejs.org/docs/latest-v14.x/api/perf_hooks.html">14.x</a></li> 359<li><a href="https://nodejs.org/docs/latest-v13.x/api/perf_hooks.html">13.x</a></li> 360<li><a href="https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html">12.x</a></li> 361<li><a href="https://nodejs.org/docs/latest-v11.x/api/perf_hooks.html">11.x</a></li> 362<li><a href="https://nodejs.org/docs/latest-v10.x/api/perf_hooks.html">10.x</a></li> 363<li><a href="https://nodejs.org/docs/latest-v9.x/api/perf_hooks.html">9.x</a></li> 364<li><a href="https://nodejs.org/docs/latest-v8.x/api/perf_hooks.html">8.x</a></li></ol></div> 365 </li> 366 367 <li class="picker-header"> 368 <a href="#"> 369 <span class="collapsed-arrow">►</span><span class="expanded-arrow">▼</span> 370 Options 371 </a> 372 373 <div class="picker"> 374 <ul> 375 <li> 376 <a href="all.html">View on single page</a> 377 </li> 378 <li> 379 <a href="perf_hooks.json">View as JSON</a> 380 </li> 381 <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/perf_hooks.md">Edit on GitHub</a></li> 382 </ul> 383 </div> 384 </li> 385 </ul> 386 </div> 387 <hr> 388 </header> 389 390 <details id="toc" open><summary>Table of contents</summary><ul> 391<li><span class="stability_2"><a href="#performance-measurement-apis">Performance measurement APIs</a></span> 392<ul> 393<li><a href="#perf_hooksperformance"><code>perf_hooks.performance</code></a> 394<ul> 395<li><a href="#performanceclearmarksname"><code>performance.clearMarks([name])</code></a></li> 396<li><a href="#performanceclearmeasuresname"><code>performance.clearMeasures([name])</code></a></li> 397<li><a href="#performanceclearresourcetimingsname"><code>performance.clearResourceTimings([name])</code></a></li> 398<li><a href="#performanceeventlooputilizationutilization1-utilization2"><code>performance.eventLoopUtilization([utilization1[, utilization2]])</code></a></li> 399<li><a href="#performancegetentries"><code>performance.getEntries()</code></a></li> 400<li><a href="#performancegetentriesbynamename-type"><code>performance.getEntriesByName(name[, type])</code></a></li> 401<li><a href="#performancegetentriesbytypetype"><code>performance.getEntriesByType(type)</code></a></li> 402<li><a href="#performancemarkname-options"><code>performance.mark([name[, options]])</code></a></li> 403<li><a href="#performancemarkresourcetimingtiminginfo-requestedurl-initiatortype-global-cachemode"><code>performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode)</code></a></li> 404<li><a href="#performancemeasurename-startmarkoroptions-endmark"><code>performance.measure(name[, startMarkOrOptions[, endMark]])</code></a></li> 405<li><a href="#performancenodetiming"><code>performance.nodeTiming</code></a></li> 406<li><a href="#performancenow"><code>performance.now()</code></a></li> 407<li><a href="#performancesetresourcetimingbuffersizemaxsize"><code>performance.setResourceTimingBufferSize(maxSize)</code></a></li> 408<li><a href="#performancetimeorigin"><code>performance.timeOrigin</code></a></li> 409<li><a href="#performancetimerifyfn-options"><code>performance.timerify(fn[, options])</code></a></li> 410<li><a href="#performancetojson"><code>performance.toJSON()</code></a> 411<ul> 412<li><a href="#event-resourcetimingbufferfull">Event: <code>'resourcetimingbufferfull'</code></a></li> 413</ul> 414</li> 415</ul> 416</li> 417<li><a href="#class-performanceentry">Class: <code>PerformanceEntry</code></a> 418<ul> 419<li><a href="#performanceentrydetail"><code>performanceEntry.detail</code></a></li> 420<li><a href="#performanceentryduration"><code>performanceEntry.duration</code></a></li> 421<li><a href="#performanceentryentrytype"><code>performanceEntry.entryType</code></a></li> 422<li><a href="#performanceentryflags"><code>performanceEntry.flags</code></a></li> 423<li><a href="#performanceentryname"><code>performanceEntry.name</code></a></li> 424<li><a href="#performanceentrykind"><code>performanceEntry.kind</code></a></li> 425<li><a href="#performanceentrystarttime"><code>performanceEntry.startTime</code></a></li> 426<li><a href="#garbage-collection-gc-details">Garbage Collection ('gc') Details</a></li> 427<li><a href="#http-http-details">HTTP ('http') Details</a></li> 428<li><a href="#http2-http2-details">HTTP/2 ('http2') Details</a></li> 429<li><a href="#timerify-function-details">Timerify ('function') Details</a></li> 430<li><a href="#net-net-details">Net ('net') Details</a></li> 431<li><a href="#dns-dns-details">DNS ('dns') Details</a></li> 432</ul> 433</li> 434<li><a href="#class-performancenodetiming">Class: <code>PerformanceNodeTiming</code></a> 435<ul> 436<li><a href="#performancenodetimingbootstrapcomplete"><code>performanceNodeTiming.bootstrapComplete</code></a></li> 437<li><a href="#performancenodetimingenvironment"><code>performanceNodeTiming.environment</code></a></li> 438<li><a href="#performancenodetimingidletime"><code>performanceNodeTiming.idleTime</code></a></li> 439<li><a href="#performancenodetimingloopexit"><code>performanceNodeTiming.loopExit</code></a></li> 440<li><a href="#performancenodetimingloopstart"><code>performanceNodeTiming.loopStart</code></a></li> 441<li><a href="#performancenodetimingnodestart"><code>performanceNodeTiming.nodeStart</code></a></li> 442<li><a href="#performancenodetimingv8start"><code>performanceNodeTiming.v8Start</code></a></li> 443</ul> 444</li> 445<li><a href="#class-performanceresourcetiming">Class: <code>PerformanceResourceTiming</code></a> 446<ul> 447<li><a href="#performanceresourcetimingworkerstart"><code>performanceResourceTiming.workerStart</code></a></li> 448<li><a href="#performanceresourcetimingredirectstart"><code>performanceResourceTiming.redirectStart</code></a></li> 449<li><a href="#performanceresourcetimingredirectend"><code>performanceResourceTiming.redirectEnd</code></a></li> 450<li><a href="#performanceresourcetimingfetchstart"><code>performanceResourceTiming.fetchStart</code></a></li> 451<li><a href="#performanceresourcetimingdomainlookupstart"><code>performanceResourceTiming.domainLookupStart</code></a></li> 452<li><a href="#performanceresourcetimingdomainlookupend"><code>performanceResourceTiming.domainLookupEnd</code></a></li> 453<li><a href="#performanceresourcetimingconnectstart"><code>performanceResourceTiming.connectStart</code></a></li> 454<li><a href="#performanceresourcetimingconnectend"><code>performanceResourceTiming.connectEnd</code></a></li> 455<li><a href="#performanceresourcetimingsecureconnectionstart"><code>performanceResourceTiming.secureConnectionStart</code></a></li> 456<li><a href="#performanceresourcetimingrequeststart"><code>performanceResourceTiming.requestStart</code></a></li> 457<li><a href="#performanceresourcetimingresponseend"><code>performanceResourceTiming.responseEnd</code></a></li> 458<li><a href="#performanceresourcetimingtransfersize"><code>performanceResourceTiming.transferSize</code></a></li> 459<li><a href="#performanceresourcetimingencodedbodysize"><code>performanceResourceTiming.encodedBodySize</code></a></li> 460<li><a href="#performanceresourcetimingdecodedbodysize"><code>performanceResourceTiming.decodedBodySize</code></a></li> 461<li><a href="#performanceresourcetimingtojson"><code>performanceResourceTiming.toJSON()</code></a></li> 462</ul> 463</li> 464<li><a href="#class-perf_hooksperformanceobserver">Class: <code>perf_hooks.PerformanceObserver</code></a> 465<ul> 466<li><a href="#performanceobserversupportedentrytypes"><code>PerformanceObserver.supportedEntryTypes</code></a></li> 467<li><a href="#new-performanceobservercallback"><code>new PerformanceObserver(callback)</code></a></li> 468<li><a href="#performanceobserverdisconnect"><code>performanceObserver.disconnect()</code></a></li> 469<li><a href="#performanceobserverobserveoptions"><code>performanceObserver.observe(options)</code></a></li> 470</ul> 471</li> 472<li><a href="#class-performanceobserverentrylist">Class: <code>PerformanceObserverEntryList</code></a> 473<ul> 474<li><a href="#performanceobserverentrylistgetentries"><code>performanceObserverEntryList.getEntries()</code></a></li> 475<li><a href="#performanceobserverentrylistgetentriesbynamename-type"><code>performanceObserverEntryList.getEntriesByName(name[, type])</code></a></li> 476<li><a href="#performanceobserverentrylistgetentriesbytypetype"><code>performanceObserverEntryList.getEntriesByType(type)</code></a></li> 477</ul> 478</li> 479<li><a href="#perf_hookscreatehistogramoptions"><code>perf_hooks.createHistogram([options])</code></a></li> 480<li><a href="#perf_hooksmonitoreventloopdelayoptions"><code>perf_hooks.monitorEventLoopDelay([options])</code></a></li> 481<li><a href="#class-histogram">Class: <code>Histogram</code></a> 482<ul> 483<li><a href="#histogramcount"><code>histogram.count</code></a></li> 484<li><a href="#histogramcountbigint"><code>histogram.countBigInt</code></a></li> 485<li><a href="#histogramexceeds"><code>histogram.exceeds</code></a></li> 486<li><a href="#histogramexceedsbigint"><code>histogram.exceedsBigInt</code></a></li> 487<li><a href="#histogrammax"><code>histogram.max</code></a></li> 488<li><a href="#histogrammaxbigint"><code>histogram.maxBigInt</code></a></li> 489<li><a href="#histogrammean"><code>histogram.mean</code></a></li> 490<li><a href="#histogrammin"><code>histogram.min</code></a></li> 491<li><a href="#histogramminbigint"><code>histogram.minBigInt</code></a></li> 492<li><a href="#histogrampercentilepercentile"><code>histogram.percentile(percentile)</code></a></li> 493<li><a href="#histogrampercentilebigintpercentile"><code>histogram.percentileBigInt(percentile)</code></a></li> 494<li><a href="#histogrampercentiles"><code>histogram.percentiles</code></a></li> 495<li><a href="#histogrampercentilesbigint"><code>histogram.percentilesBigInt</code></a></li> 496<li><a href="#histogramreset"><code>histogram.reset()</code></a></li> 497<li><a href="#histogramstddev"><code>histogram.stddev</code></a></li> 498</ul> 499</li> 500<li><a href="#class-intervalhistogram-extends-histogram">Class: <code>IntervalHistogram extends Histogram</code></a> 501<ul> 502<li><a href="#histogramdisable"><code>histogram.disable()</code></a></li> 503<li><a href="#histogramenable"><code>histogram.enable()</code></a></li> 504<li><a href="#cloning-an-intervalhistogram">Cloning an <code>IntervalHistogram</code></a></li> 505</ul> 506</li> 507<li><a href="#class-recordablehistogram-extends-histogram">Class: <code>RecordableHistogram extends Histogram</code></a> 508<ul> 509<li><a href="#histogramaddother"><code>histogram.add(other)</code></a></li> 510<li><a href="#histogramrecordval"><code>histogram.record(val)</code></a></li> 511<li><a href="#histogramrecorddelta"><code>histogram.recordDelta()</code></a></li> 512</ul> 513</li> 514<li><a href="#examples">Examples</a> 515<ul> 516<li><a href="#measuring-the-duration-of-async-operations">Measuring the duration of async operations</a></li> 517<li><a href="#measuring-how-long-it-takes-to-load-dependencies">Measuring how long it takes to load dependencies</a></li> 518<li><a href="#measuring-how-long-one-http-round-trip-takes">Measuring how long one HTTP round-trip takes</a></li> 519<li><a href="#measuring-how-long-the-netconnect-only-for-tcp-takes-when-the-connection-is-successful">Measuring how long the <code>net.connect</code> (only for TCP) takes when the connection is successful</a></li> 520<li><a href="#measuring-how-long-the-dns-takes-when-the-request-is-successful">Measuring how long the DNS takes when the request is successful</a></li> 521</ul> 522</li> 523</ul> 524</li> 525</ul></details> 526 527 <div id="apicontent"> 528 <h2>Performance measurement APIs<span><a class="mark" href="#performance-measurement-apis" id="performance-measurement-apis">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_measurement_apis"></a></h2> 529 530<p></p><div class="api_stability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</div><p></p> 531<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/perf_hooks.js">lib/perf_hooks.js</a></p> 532<p>This module provides an implementation of a subset of the W3C 533<a href="https://w3c.github.io/perf-timing-primer/">Web Performance APIs</a> as well as additional APIs for 534Node.js-specific performance measurements.</p> 535<p>Node.js supports the following <a href="https://w3c.github.io/perf-timing-primer/">Web Performance APIs</a>:</p> 536<ul> 537<li><a href="https://www.w3.org/TR/hr-time-2">High Resolution Time</a></li> 538<li><a href="https://w3c.github.io/performance-timeline/">Performance Timeline</a></li> 539<li><a href="https://www.w3.org/TR/user-timing/">User Timing</a></li> 540<li><a href="https://www.w3.org/TR/resource-timing-2/">Resource Timing</a></li> 541</ul> 542<pre><code class="language-js"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">PerformanceObserver</span>, performance } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 543 544<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">items</span>) =></span> { 545 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(items.<span class="hljs-title function_">getEntries</span>()[<span class="hljs-number">0</span>].<span class="hljs-property">duration</span>); 546 performance.<span class="hljs-title function_">clearMarks</span>(); 547}); 548obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'measure'</span> }); 549performance.<span class="hljs-title function_">measure</span>(<span class="hljs-string">'Start to Now'</span>); 550 551performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'A'</span>); 552<span class="hljs-title function_">doSomeLongRunningProcess</span>(<span class="hljs-function">() =></span> { 553 performance.<span class="hljs-title function_">measure</span>(<span class="hljs-string">'A to Now'</span>, <span class="hljs-string">'A'</span>); 554 555 performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'B'</span>); 556 performance.<span class="hljs-title function_">measure</span>(<span class="hljs-string">'A to B'</span>, <span class="hljs-string">'A'</span>, <span class="hljs-string">'B'</span>); 557});</code> <button class="copy-button">copy</button></pre> 558<section><h3><code>perf_hooks.performance</code><span><a class="mark" href="#perf_hooksperformance" id="perf_hooksperformance">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_perf_hooks_performance"></a></h3> 559<div class="api_metadata"> 560<span>Added in: v8.5.0</span> 561</div> 562<p>An object that can be used to collect performance metrics from the current 563Node.js instance. It is similar to <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/performance"><code>window.performance</code></a> in browsers.</p> 564<h4><code>performance.clearMarks([name])</code><span><a class="mark" href="#performanceclearmarksname" id="performanceclearmarksname">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_clearmarks_name"></a></h4> 565<div class="api_metadata"> 566<span>Added in: v8.5.0</span> 567</div> 568<ul> 569<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 570</ul> 571<p>If <code>name</code> is not provided, removes all <code>PerformanceMark</code> objects from the 572Performance Timeline. If <code>name</code> is provided, removes only the named mark.</p> 573<h4><code>performance.clearMeasures([name])</code><span><a class="mark" href="#performanceclearmeasuresname" id="performanceclearmeasuresname">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_clearmeasures_name"></a></h4> 574<div class="api_metadata"> 575<span>Added in: v16.7.0</span> 576</div> 577<ul> 578<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 579</ul> 580<p>If <code>name</code> is not provided, removes all <code>PerformanceMeasure</code> objects from the 581Performance Timeline. If <code>name</code> is provided, removes only the named measure.</p> 582<h4><code>performance.clearResourceTimings([name])</code><span><a class="mark" href="#performanceclearresourcetimingsname" id="performanceclearresourcetimingsname">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_clearresourcetimings_name"></a></h4> 583<div class="api_metadata"> 584<span>Added in: v18.2.0</span> 585</div> 586<ul> 587<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 588</ul> 589<p>If <code>name</code> is not provided, removes all <code>PerformanceResourceTiming</code> objects from 590the Resource Timeline. If <code>name</code> is provided, removes only the named resource.</p> 591<h4><code>performance.eventLoopUtilization([utilization1[, utilization2]])</code><span><a class="mark" href="#performanceeventlooputilizationutilization1-utilization2" id="performanceeventlooputilizationutilization1-utilization2">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_eventlooputilization_utilization1_utilization2"></a></h4> 592<div class="api_metadata"> 593<span>Added in: v14.10.0, v12.19.0</span> 594</div> 595<ul> 596<li><code>utilization1</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> The result of a previous call to 597<code>eventLoopUtilization()</code>.</li> 598<li><code>utilization2</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> The result of a previous call to 599<code>eventLoopUtilization()</code> prior to <code>utilization1</code>.</li> 600<li>Returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 601<ul> 602<li><code>idle</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 603<li><code>active</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 604<li><code>utilization</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 605</ul> 606</li> 607</ul> 608<p>The <code>eventLoopUtilization()</code> method returns an object that contains the 609cumulative duration of time the event loop has been both idle and active as a 610high resolution milliseconds timer. The <code>utilization</code> value is the calculated 611Event Loop Utilization (ELU).</p> 612<p>If bootstrapping has not yet finished on the main thread the properties have 613the value of <code>0</code>. The ELU is immediately available on <a href="worker_threads.html#worker-threads">Worker threads</a> since 614bootstrap happens within the event loop.</p> 615<p>Both <code>utilization1</code> and <code>utilization2</code> are optional parameters.</p> 616<p>If <code>utilization1</code> is passed, then the delta between the current call's <code>active</code> 617and <code>idle</code> times, as well as the corresponding <code>utilization</code> value are 618calculated and returned (similar to <a href="process.html#processhrtimetime"><code>process.hrtime()</code></a>).</p> 619<p>If <code>utilization1</code> and <code>utilization2</code> are both passed, then the delta is 620calculated between the two arguments. This is a convenience option because, 621unlike <a href="process.html#processhrtimetime"><code>process.hrtime()</code></a>, calculating the ELU is more complex than a 622single subtraction.</p> 623<p>ELU is similar to CPU utilization, except that it only measures event loop 624statistics and not CPU usage. It represents the percentage of time the event 625loop has spent outside the event loop's event provider (e.g. <code>epoll_wait</code>). 626No other CPU idle time is taken into consideration. The following is an example 627of how a mostly idle process will have a high ELU.</p> 628<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>; 629<span class="hljs-keyword">const</span> { eventLoopUtilization } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>).<span class="hljs-property">performance</span>; 630<span class="hljs-keyword">const</span> { spawnSync } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:child_process'</span>); 631 632<span class="hljs-title function_">setImmediate</span>(<span class="hljs-function">() =></span> { 633 <span class="hljs-keyword">const</span> elu = <span class="hljs-title function_">eventLoopUtilization</span>(); 634 <span class="hljs-title function_">spawnSync</span>(<span class="hljs-string">'sleep'</span>, [<span class="hljs-string">'5'</span>]); 635 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title function_">eventLoopUtilization</span>(elu).<span class="hljs-property">utilization</span>); 636});</code> <button class="copy-button">copy</button></pre> 637<p>Although the CPU is mostly idle while running this script, the value of 638<code>utilization</code> is <code>1</code>. This is because the call to 639<a href="child_process.html#child_processspawnsynccommand-args-options"><code>child_process.spawnSync()</code></a> blocks the event loop from proceeding.</p> 640<p>Passing in a user-defined object instead of the result of a previous call to 641<code>eventLoopUtilization()</code> will lead to undefined behavior. The return values 642are not guaranteed to reflect any correct state of the event loop.</p> 643<h4><code>performance.getEntries()</code><span><a class="mark" href="#performancegetentries" id="performancegetentries">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_getentries"></a></h4> 644<div class="api_metadata"> 645<span>Added in: v16.7.0</span> 646</div> 647<ul> 648<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry[]></a></li> 649</ul> 650<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order with 651respect to <code>performanceEntry.startTime</code>. If you are only interested in 652performance entries of certain types or that have certain names, see 653<code>performance.getEntriesByType()</code> and <code>performance.getEntriesByName()</code>.</p> 654<h4><code>performance.getEntriesByName(name[, type])</code><span><a class="mark" href="#performancegetentriesbynamename-type" id="performancegetentriesbynamename-type">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_getentriesbyname_name_type"></a></h4> 655<div class="api_metadata"> 656<span>Added in: v16.7.0</span> 657</div> 658<ul> 659<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 660<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 661<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry[]></a></li> 662</ul> 663<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order 664with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.name</code> is 665equal to <code>name</code>, and optionally, whose <code>performanceEntry.entryType</code> is equal to 666<code>type</code>.</p> 667<h4><code>performance.getEntriesByType(type)</code><span><a class="mark" href="#performancegetentriesbytypetype" id="performancegetentriesbytypetype">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_getentriesbytype_type"></a></h4> 668<div class="api_metadata"> 669<span>Added in: v16.7.0</span> 670</div> 671<ul> 672<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 673<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry[]></a></li> 674</ul> 675<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order 676with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.entryType</code> 677is equal to <code>type</code>.</p> 678<h4><code>performance.mark([name[, options]])</code><span><a class="mark" href="#performancemarkname-options" id="performancemarkname-options">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_mark_name_options"></a></h4> 679<div class="api_metadata"> 680<details class="changelog"><summary>History</summary> 681<table> 682<tbody><tr><th>Version</th><th>Changes</th></tr> 683<tr><td>v16.0.0</td> 684<td><p>Updated to conform to the User Timing Level 3 specification.</p></td></tr> 685<tr><td>v8.5.0</td> 686<td><p><span>Added in: v8.5.0</span></p></td></tr> 687</tbody></table> 688</details> 689</div> 690<ul> 691<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 692<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 693<ul> 694<li><code>detail</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> Additional optional detail to include with the mark.</li> 695<li><code>startTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> An optional timestamp to be used as the mark time. 696<strong>Default</strong>: <code>performance.now()</code>.</li> 697</ul> 698</li> 699</ul> 700<p>Creates a new <code>PerformanceMark</code> entry in the Performance Timeline. A 701<code>PerformanceMark</code> is a subclass of <code>PerformanceEntry</code> whose 702<code>performanceEntry.entryType</code> is always <code>'mark'</code>, and whose 703<code>performanceEntry.duration</code> is always <code>0</code>. Performance marks are used 704to mark specific significant moments in the Performance Timeline.</p> 705<p>The created <code>PerformanceMark</code> entry is put in the global Performance Timeline 706and can be queried with <code>performance.getEntries</code>, 707<code>performance.getEntriesByName</code>, and <code>performance.getEntriesByType</code>. When the 708observation is performed, the entries should be cleared from the global 709Performance Timeline manually with <code>performance.clearMarks</code>.</p> 710<h4><code>performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode)</code><span><a class="mark" href="#performancemarkresourcetimingtiminginfo-requestedurl-initiatortype-global-cachemode" id="performancemarkresourcetimingtiminginfo-requestedurl-initiatortype-global-cachemode">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_markresourcetiming_timinginfo_requestedurl_initiatortype_global_cachemode"></a></h4> 711<div class="api_metadata"> 712<span>Added in: v18.2.0</span> 713</div> 714<ul> 715<li><code>timingInfo</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> <a href="https://fetch.spec.whatwg.org/#fetch-timing-info">Fetch Timing Info</a></li> 716<li><code>requestedUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The resource url</li> 717<li><code>initiatorType</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The initiator name, e.g: 'fetch'</li> 718<li><code>global</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a></li> 719<li><code>cacheMode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> The cache mode must be an empty string ('') or 'local'</li> 720</ul> 721<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p> 722<p>Creates a new <code>PerformanceResourceTiming</code> entry in the Resource Timeline. A 723<code>PerformanceResourceTiming</code> is a subclass of <code>PerformanceEntry</code> whose 724<code>performanceEntry.entryType</code> is always <code>'resource'</code>. Performance resources 725are used to mark moments in the Resource Timeline.</p> 726<p>The created <code>PerformanceMark</code> entry is put in the global Resource Timeline 727and can be queried with <code>performance.getEntries</code>, 728<code>performance.getEntriesByName</code>, and <code>performance.getEntriesByType</code>. When the 729observation is performed, the entries should be cleared from the global 730Performance Timeline manually with <code>performance.clearResourceTimings</code>.</p> 731<h4><code>performance.measure(name[, startMarkOrOptions[, endMark]])</code><span><a class="mark" href="#performancemeasurename-startmarkoroptions-endmark" id="performancemeasurename-startmarkoroptions-endmark">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_measure_name_startmarkoroptions_endmark"></a></h4> 732<div class="api_metadata"> 733<details class="changelog"><summary>History</summary> 734<table> 735<tbody><tr><th>Version</th><th>Changes</th></tr> 736<tr><td>v16.0.0</td> 737<td><p>Updated to conform to the User Timing Level 3 specification.</p></td></tr> 738<tr><td>v13.13.0, v12.16.3</td> 739<td><p>Make <code>startMark</code> and <code>endMark</code> parameters optional.</p></td></tr> 740<tr><td>v8.5.0</td> 741<td><p><span>Added in: v8.5.0</span></p></td></tr> 742</tbody></table> 743</details> 744</div> 745<ul> 746<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 747<li><code>startMarkOrOptions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> Optional. 748<ul> 749<li><code>detail</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a> Additional optional detail to include with the measure.</li> 750<li><code>duration</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> Duration between start and end times.</li> 751<li><code>end</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Timestamp to be used as the end time, or a string 752identifying a previously recorded mark.</li> 753<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Timestamp to be used as the start time, or a string 754identifying a previously recorded mark.</li> 755</ul> 756</li> 757<li><code>endMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Optional. Must be omitted if <code>startMarkOrOptions</code> is an 758<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a>.</li> 759</ul> 760<p>Creates a new <code>PerformanceMeasure</code> entry in the Performance Timeline. A 761<code>PerformanceMeasure</code> is a subclass of <code>PerformanceEntry</code> whose 762<code>performanceEntry.entryType</code> is always <code>'measure'</code>, and whose 763<code>performanceEntry.duration</code> measures the number of milliseconds elapsed since 764<code>startMark</code> and <code>endMark</code>.</p> 765<p>The <code>startMark</code> argument may identify any <em>existing</em> <code>PerformanceMark</code> in the 766Performance Timeline, or <em>may</em> identify any of the timestamp properties 767provided by the <code>PerformanceNodeTiming</code> class. If the named <code>startMark</code> does 768not exist, an error is thrown.</p> 769<p>The optional <code>endMark</code> argument must identify any <em>existing</em> <code>PerformanceMark</code> 770in the Performance Timeline or any of the timestamp properties provided by the 771<code>PerformanceNodeTiming</code> class. <code>endMark</code> will be <code>performance.now()</code> 772if no parameter is passed, otherwise if the named <code>endMark</code> does not exist, an 773error will be thrown.</p> 774<p>The created <code>PerformanceMeasure</code> entry is put in the global Performance Timeline 775and can be queried with <code>performance.getEntries</code>, 776<code>performance.getEntriesByName</code>, and <code>performance.getEntriesByType</code>. When the 777observation is performed, the entries should be cleared from the global 778Performance Timeline manually with <code>performance.clearMeasures</code>.</p> 779<h4><code>performance.nodeTiming</code><span><a class="mark" href="#performancenodetiming" id="performancenodetiming">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_nodetiming"></a></h4> 780<div class="api_metadata"> 781<span>Added in: v8.5.0</span> 782</div> 783<ul> 784<li><a href="perf_hooks.html#class-performancenodetiming" class="type"><PerformanceNodeTiming></a></li> 785</ul> 786<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p> 787<p>An instance of the <code>PerformanceNodeTiming</code> class that provides performance 788metrics for specific Node.js operational milestones.</p> 789<h4><code>performance.now()</code><span><a class="mark" href="#performancenow" id="performancenow">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_now"></a></h4> 790<div class="api_metadata"> 791<span>Added in: v8.5.0</span> 792</div> 793<ul> 794<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 795</ul> 796<p>Returns the current high resolution millisecond timestamp, where 0 represents 797the start of the current <code>node</code> process.</p> 798<h4><code>performance.setResourceTimingBufferSize(maxSize)</code><span><a class="mark" href="#performancesetresourcetimingbuffersizemaxsize" id="performancesetresourcetimingbuffersizemaxsize">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_setresourcetimingbuffersize_maxsize"></a></h4> 799<div class="api_metadata"> 800<span>Added in: v18.8.0</span> 801</div> 802<p>Sets the global performance resource timing buffer size to the specified number 803of "resource" type performance entry objects.</p> 804<p>By default the max buffer size is set to 250.</p> 805<h4><code>performance.timeOrigin</code><span><a class="mark" href="#performancetimeorigin" id="performancetimeorigin">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_timeorigin"></a></h4> 806<div class="api_metadata"> 807<span>Added in: v8.5.0</span> 808</div> 809<ul> 810<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 811</ul> 812<p>The <a href="https://w3c.github.io/hr-time/#dom-performance-timeorigin"><code>timeOrigin</code></a> specifies the high resolution millisecond timestamp at 813which the current <code>node</code> process began, measured in Unix time.</p> 814<h4><code>performance.timerify(fn[, options])</code><span><a class="mark" href="#performancetimerifyfn-options" id="performancetimerifyfn-options">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_timerify_fn_options"></a></h4> 815<div class="api_metadata"> 816<details class="changelog"><summary>History</summary> 817<table> 818<tbody><tr><th>Version</th><th>Changes</th></tr> 819<tr><td>v16.0.0</td> 820<td><p>Added the histogram option.</p></td></tr> 821<tr><td>v16.0.0</td> 822<td><p>Re-implemented to use pure-JavaScript and the ability to time async functions.</p></td></tr> 823<tr><td>v8.5.0</td> 824<td><p><span>Added in: v8.5.0</span></p></td></tr> 825</tbody></table> 826</details> 827</div> 828<ul> 829<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a></li> 830<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 831<ul> 832<li><code>histogram</code> <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type"><RecordableHistogram></a> A histogram object created using 833<code>perf_hooks.createHistogram()</code> that will record runtime durations in 834nanoseconds.</li> 835</ul> 836</li> 837</ul> 838<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p> 839<p>Wraps a function within a new function that measures the running time of the 840wrapped function. A <code>PerformanceObserver</code> must be subscribed to the <code>'function'</code> 841event type in order for the timing details to be accessed.</p> 842<pre><code class="language-js"><span class="hljs-keyword">const</span> { 843 performance, 844 <span class="hljs-title class_">PerformanceObserver</span>, 845} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 846 847<span class="hljs-keyword">function</span> <span class="hljs-title function_">someFunction</span>(<span class="hljs-params"></span>) { 848 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'hello world'</span>); 849} 850 851<span class="hljs-keyword">const</span> wrapped = performance.<span class="hljs-title function_">timerify</span>(someFunction); 852 853<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">list</span>) =></span> { 854 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(list.<span class="hljs-title function_">getEntries</span>()[<span class="hljs-number">0</span>].<span class="hljs-property">duration</span>); 855 856 performance.<span class="hljs-title function_">clearMarks</span>(); 857 performance.<span class="hljs-title function_">clearMeasures</span>(); 858 obs.<span class="hljs-title function_">disconnect</span>(); 859}); 860obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'function'</span>] }); 861 862<span class="hljs-comment">// A performance timeline entry will be created</span> 863<span class="hljs-title function_">wrapped</span>();</code> <button class="copy-button">copy</button></pre> 864<p>If the wrapped function returns a promise, a finally handler will be attached 865to the promise and the duration will be reported once the finally handler is 866invoked.</p> 867<h4><code>performance.toJSON()</code><span><a class="mark" href="#performancetojson" id="performancetojson">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performance_tojson"></a></h4> 868<div class="api_metadata"> 869<span>Added in: v16.1.0</span> 870</div> 871<p>An object which is JSON representation of the <code>performance</code> object. It 872is similar to <a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance/toJSON"><code>window.performance.toJSON</code></a> in browsers.</p> 873<h5>Event: <code>'resourcetimingbufferfull'</code><span><a class="mark" href="#event-resourcetimingbufferfull" id="event-resourcetimingbufferfull">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_event_resourcetimingbufferfull"></a></h5> 874<div class="api_metadata"> 875<span>Added in: v18.8.0</span> 876</div> 877<p>The <code>'resourcetimingbufferfull'</code> event is fired when the global performance 878resource timing buffer is full. Adjust resource timing buffer size with 879<code>performance.setResourceTimingBufferSize()</code> or clear the buffer with 880<code>performance.clearResourceTimings()</code> in the event listener to allow 881more entries to be added to the performance timeline buffer.</p> 882</section><section><h3>Class: <code>PerformanceEntry</code><span><a class="mark" href="#class-performanceentry" id="class-performanceentry">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_performanceentry"></a></h3> 883<div class="api_metadata"> 884<span>Added in: v8.5.0</span> 885</div> 886<h4><code>performanceEntry.detail</code><span><a class="mark" href="#performanceentrydetail" id="performanceentrydetail">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceentry_detail"></a></h4> 887<div class="api_metadata"> 888<span>Added in: v16.0.0</span> 889</div> 890<ul> 891<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type"><any></a></li> 892</ul> 893<p>Additional detail specific to the <code>entryType</code>.</p> 894<h4><code>performanceEntry.duration</code><span><a class="mark" href="#performanceentryduration" id="performanceentryduration">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceentry_duration"></a></h4> 895<div class="api_metadata"> 896<span>Added in: v8.5.0</span> 897</div> 898<ul> 899<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 900</ul> 901<p>The total number of milliseconds elapsed for this entry. This value will not 902be meaningful for all Performance Entry types.</p> 903<h4><code>performanceEntry.entryType</code><span><a class="mark" href="#performanceentryentrytype" id="performanceentryentrytype">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceentry_entrytype"></a></h4> 904<div class="api_metadata"> 905<span>Added in: v8.5.0</span> 906</div> 907<ul> 908<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 909</ul> 910<p>The type of the performance entry. It may be one of:</p> 911<ul> 912<li><code>'node'</code> (Node.js only)</li> 913<li><code>'mark'</code> (available on the Web)</li> 914<li><code>'measure'</code> (available on the Web)</li> 915<li><code>'gc'</code> (Node.js only)</li> 916<li><code>'function'</code> (Node.js only)</li> 917<li><code>'http2'</code> (Node.js only)</li> 918<li><code>'http'</code> (Node.js only)</li> 919</ul> 920<h4><code>performanceEntry.flags</code><span><a class="mark" href="#performanceentryflags" id="performanceentryflags">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceentry_flags"></a></h4> 921<div class="api_metadata"> 922<details class="changelog"><summary>History</summary> 923<table> 924<tbody><tr><th>Version</th><th>Changes</th></tr> 925<tr><td>v16.0.0</td> 926<td><p>Runtime deprecated. Now moved to the detail property when entryType is 'gc'.</p></td></tr> 927<tr><td>v13.9.0, v12.17.0</td> 928<td><p><span>Added in: v13.9.0, v12.17.0</span></p></td></tr> 929</tbody></table> 930</details> 931</div> 932<ul> 933<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 934</ul> 935<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p> 936<p>When <code>performanceEntry.entryType</code> is equal to <code>'gc'</code>, the <code>performance.flags</code> 937property contains additional information about garbage collection operation. 938The value may be one of:</p> 939<ul> 940<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO</code></li> 941<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED</code></li> 942<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED</code></li> 943<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING</code></li> 944<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE</code></li> 945<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY</code></li> 946<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE</code></li> 947</ul> 948<h4><code>performanceEntry.name</code><span><a class="mark" href="#performanceentryname" id="performanceentryname">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceentry_name"></a></h4> 949<div class="api_metadata"> 950<span>Added in: v8.5.0</span> 951</div> 952<ul> 953<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 954</ul> 955<p>The name of the performance entry.</p> 956<h4><code>performanceEntry.kind</code><span><a class="mark" href="#performanceentrykind" id="performanceentrykind">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceentry_kind"></a></h4> 957<div class="api_metadata"> 958<details class="changelog"><summary>History</summary> 959<table> 960<tbody><tr><th>Version</th><th>Changes</th></tr> 961<tr><td>v16.0.0</td> 962<td><p>Runtime deprecated. Now moved to the detail property when entryType is 'gc'.</p></td></tr> 963<tr><td>v8.5.0</td> 964<td><p><span>Added in: v8.5.0</span></p></td></tr> 965</tbody></table> 966</details> 967</div> 968<ul> 969<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 970</ul> 971<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p> 972<p>When <code>performanceEntry.entryType</code> is equal to <code>'gc'</code>, the <code>performance.kind</code> 973property identifies the type of garbage collection operation that occurred. 974The value may be one of:</p> 975<ul> 976<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR</code></li> 977<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR</code></li> 978<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL</code></li> 979<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB</code></li> 980</ul> 981<h4><code>performanceEntry.startTime</code><span><a class="mark" href="#performanceentrystarttime" id="performanceentrystarttime">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceentry_starttime"></a></h4> 982<div class="api_metadata"> 983<span>Added in: v8.5.0</span> 984</div> 985<ul> 986<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 987</ul> 988<p>The high resolution millisecond timestamp marking the starting time of the 989Performance Entry.</p> 990<h4>Garbage Collection ('gc') Details<span><a class="mark" href="#garbage-collection-gc-details" id="garbage-collection-gc-details">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_garbage_collection_gc_details"></a></h4> 991<p>When <code>performanceEntry.type</code> is equal to <code>'gc'</code>, the <code>performanceEntry.detail</code> 992property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> with two properties:</p> 993<ul> 994<li><code>kind</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> One of: 995<ul> 996<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR</code></li> 997<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR</code></li> 998<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL</code></li> 999<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB</code></li> 1000</ul> 1001</li> 1002<li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> One of: 1003<ul> 1004<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO</code></li> 1005<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED</code></li> 1006<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED</code></li> 1007<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING</code></li> 1008<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE</code></li> 1009<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY</code></li> 1010<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE</code></li> 1011</ul> 1012</li> 1013</ul> 1014<h4>HTTP ('http') Details<span><a class="mark" href="#http-http-details" id="http-http-details">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_http_http_details"></a></h4> 1015<p>When <code>performanceEntry.type</code> is equal to <code>'http'</code>, the <code>performanceEntry.detail</code> 1016property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing additional information.</p> 1017<p>If <code>performanceEntry.name</code> is equal to <code>HttpClient</code>, the <code>detail</code> 1018will contain the following properties: <code>req</code>, <code>res</code>. And the <code>req</code> property 1019will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing <code>method</code>, <code>url</code>, <code>headers</code>, the <code>res</code> property 1020will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing <code>statusCode</code>, <code>statusMessage</code>, <code>headers</code>.</p> 1021<p>If <code>performanceEntry.name</code> is equal to <code>HttpRequest</code>, the <code>detail</code> 1022will contain the following properties: <code>req</code>, <code>res</code>. And the <code>req</code> property 1023will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing <code>method</code>, <code>url</code>, <code>headers</code>, the <code>res</code> property 1024will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing <code>statusCode</code>, <code>statusMessage</code>, <code>headers</code>.</p> 1025<p>This could add additional memory overhead and should only be used for 1026diagnostic purposes, not left turned on in production by default.</p> 1027<h4>HTTP/2 ('http2') Details<span><a class="mark" href="#http2-http2-details" id="http2-http2-details">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_http_2_http2_details"></a></h4> 1028<p>When <code>performanceEntry.type</code> is equal to <code>'http2'</code>, the 1029<code>performanceEntry.detail</code> property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing 1030additional performance information.</p> 1031<p>If <code>performanceEntry.name</code> is equal to <code>Http2Stream</code>, the <code>detail</code> 1032will contain the following properties:</p> 1033<ul> 1034<li><code>bytesRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of <code>DATA</code> frame bytes received for this 1035<code>Http2Stream</code>.</li> 1036<li><code>bytesWritten</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of <code>DATA</code> frame bytes sent for this 1037<code>Http2Stream</code>.</li> 1038<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The identifier of the associated <code>Http2Stream</code></li> 1039<li><code>timeToFirstByte</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of milliseconds elapsed between the 1040<code>PerformanceEntry</code> <code>startTime</code> and the reception of the first <code>DATA</code> frame.</li> 1041<li><code>timeToFirstByteSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of milliseconds elapsed between 1042the <code>PerformanceEntry</code> <code>startTime</code> and sending of the first <code>DATA</code> frame.</li> 1043<li><code>timeToFirstHeader</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of milliseconds elapsed between the 1044<code>PerformanceEntry</code> <code>startTime</code> and the reception of the first header.</li> 1045</ul> 1046<p>If <code>performanceEntry.name</code> is equal to <code>Http2Session</code>, the <code>detail</code> will 1047contain the following properties:</p> 1048<ul> 1049<li><code>bytesRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of bytes received for this <code>Http2Session</code>.</li> 1050<li><code>bytesWritten</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of bytes sent for this <code>Http2Session</code>.</li> 1051<li><code>framesReceived</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of HTTP/2 frames received by the 1052<code>Http2Session</code>.</li> 1053<li><code>framesSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of HTTP/2 frames sent by the <code>Http2Session</code>.</li> 1054<li><code>maxConcurrentStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The maximum number of streams concurrently 1055open during the lifetime of the <code>Http2Session</code>.</li> 1056<li><code>pingRTT</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of milliseconds elapsed since the transmission 1057of a <code>PING</code> frame and the reception of its acknowledgment. Only present if 1058a <code>PING</code> frame has been sent on the <code>Http2Session</code>.</li> 1059<li><code>streamAverageDuration</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The average duration (in milliseconds) for 1060all <code>Http2Stream</code> instances.</li> 1061<li><code>streamCount</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of <code>Http2Stream</code> instances processed by 1062the <code>Http2Session</code>.</li> 1063<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> Either <code>'server'</code> or <code>'client'</code> to identify the type of 1064<code>Http2Session</code>.</li> 1065</ul> 1066<h4>Timerify ('function') Details<span><a class="mark" href="#timerify-function-details" id="timerify-function-details">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_timerify_function_details"></a></h4> 1067<p>When <code>performanceEntry.type</code> is equal to <code>'function'</code>, the 1068<code>performanceEntry.detail</code> property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" class="type"><Array></a> listing 1069the input arguments to the timed function.</p> 1070<h4>Net ('net') Details<span><a class="mark" href="#net-net-details" id="net-net-details">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_net_net_details"></a></h4> 1071<p>When <code>performanceEntry.type</code> is equal to <code>'net'</code>, the 1072<code>performanceEntry.detail</code> property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing 1073additional information.</p> 1074<p>If <code>performanceEntry.name</code> is equal to <code>connect</code>, the <code>detail</code> 1075will contain the following properties: <code>host</code>, <code>port</code>.</p> 1076<h4>DNS ('dns') Details<span><a class="mark" href="#dns-dns-details" id="dns-dns-details">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_dns_dns_details"></a></h4> 1077<p>When <code>performanceEntry.type</code> is equal to <code>'dns'</code>, the 1078<code>performanceEntry.detail</code> property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> containing 1079additional information.</p> 1080<p>If <code>performanceEntry.name</code> is equal to <code>lookup</code>, the <code>detail</code> 1081will contain the following properties: <code>hostname</code>, <code>family</code>, <code>hints</code>, <code>verbatim</code>, 1082<code>addresses</code>.</p> 1083<p>If <code>performanceEntry.name</code> is equal to <code>lookupService</code>, the <code>detail</code> will 1084contain the following properties: <code>host</code>, <code>port</code>, <code>hostname</code>, <code>service</code>.</p> 1085<p>If <code>performanceEntry.name</code> is equal to <code>queryxxx</code> or <code>getHostByAddr</code>, the <code>detail</code> will 1086contain the following properties: <code>host</code>, <code>ttl</code>, <code>result</code>. The value of <code>result</code> is 1087same as the result of <code>queryxxx</code> or <code>getHostByAddr</code>.</p> 1088</section><section><h3>Class: <code>PerformanceNodeTiming</code><span><a class="mark" href="#class-performancenodetiming" id="class-performancenodetiming">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_performancenodetiming"></a></h3> 1089<div class="api_metadata"> 1090<span>Added in: v8.5.0</span> 1091</div> 1092<ul> 1093<li>Extends: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry></a></li> 1094</ul> 1095<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p> 1096<p>Provides timing details for Node.js itself. The constructor of this class 1097is not exposed to users.</p> 1098<h4><code>performanceNodeTiming.bootstrapComplete</code><span><a class="mark" href="#performancenodetimingbootstrapcomplete" id="performancenodetimingbootstrapcomplete">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performancenodetiming_bootstrapcomplete"></a></h4> 1099<div class="api_metadata"> 1100<span>Added in: v8.5.0</span> 1101</div> 1102<ul> 1103<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1104</ul> 1105<p>The high resolution millisecond timestamp at which the Node.js process 1106completed bootstrapping. If bootstrapping has not yet finished, the property 1107has the value of -1.</p> 1108<h4><code>performanceNodeTiming.environment</code><span><a class="mark" href="#performancenodetimingenvironment" id="performancenodetimingenvironment">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performancenodetiming_environment"></a></h4> 1109<div class="api_metadata"> 1110<span>Added in: v8.5.0</span> 1111</div> 1112<ul> 1113<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1114</ul> 1115<p>The high resolution millisecond timestamp at which the Node.js environment was 1116initialized.</p> 1117<h4><code>performanceNodeTiming.idleTime</code><span><a class="mark" href="#performancenodetimingidletime" id="performancenodetimingidletime">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performancenodetiming_idletime"></a></h4> 1118<div class="api_metadata"> 1119<span>Added in: v14.10.0, v12.19.0</span> 1120</div> 1121<ul> 1122<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1123</ul> 1124<p>The high resolution millisecond timestamp of the amount of time the event loop 1125has been idle within the event loop's event provider (e.g. <code>epoll_wait</code>). This 1126does not take CPU usage into consideration. If the event loop has not yet 1127started (e.g., in the first tick of the main script), the property has the 1128value of 0.</p> 1129<h4><code>performanceNodeTiming.loopExit</code><span><a class="mark" href="#performancenodetimingloopexit" id="performancenodetimingloopexit">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performancenodetiming_loopexit"></a></h4> 1130<div class="api_metadata"> 1131<span>Added in: v8.5.0</span> 1132</div> 1133<ul> 1134<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1135</ul> 1136<p>The high resolution millisecond timestamp at which the Node.js event loop 1137exited. If the event loop has not yet exited, the property has the value of -1. 1138It can only have a value of not -1 in a handler of the <a href="process.html#event-exit"><code>'exit'</code></a> event.</p> 1139<h4><code>performanceNodeTiming.loopStart</code><span><a class="mark" href="#performancenodetimingloopstart" id="performancenodetimingloopstart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performancenodetiming_loopstart"></a></h4> 1140<div class="api_metadata"> 1141<span>Added in: v8.5.0</span> 1142</div> 1143<ul> 1144<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1145</ul> 1146<p>The high resolution millisecond timestamp at which the Node.js event loop 1147started. If the event loop has not yet started (e.g., in the first tick of the 1148main script), the property has the value of -1.</p> 1149<h4><code>performanceNodeTiming.nodeStart</code><span><a class="mark" href="#performancenodetimingnodestart" id="performancenodetimingnodestart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performancenodetiming_nodestart"></a></h4> 1150<div class="api_metadata"> 1151<span>Added in: v8.5.0</span> 1152</div> 1153<ul> 1154<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1155</ul> 1156<p>The high resolution millisecond timestamp at which the Node.js process was 1157initialized.</p> 1158<h4><code>performanceNodeTiming.v8Start</code><span><a class="mark" href="#performancenodetimingv8start" id="performancenodetimingv8start">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performancenodetiming_v8start"></a></h4> 1159<div class="api_metadata"> 1160<span>Added in: v8.5.0</span> 1161</div> 1162<ul> 1163<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1164</ul> 1165<p>The high resolution millisecond timestamp at which the V8 platform was 1166initialized.</p> 1167</section><section><h3>Class: <code>PerformanceResourceTiming</code><span><a class="mark" href="#class-performanceresourcetiming" id="class-performanceresourcetiming">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_performanceresourcetiming"></a></h3> 1168<div class="api_metadata"> 1169<span>Added in: v18.2.0</span> 1170</div> 1171<ul> 1172<li>Extends: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry></a></li> 1173</ul> 1174<p>Provides detailed network timing data regarding the loading of an application's 1175resources.</p> 1176<p>The constructor of this class is not exposed to users directly.</p> 1177<h4><code>performanceResourceTiming.workerStart</code><span><a class="mark" href="#performanceresourcetimingworkerstart" id="performanceresourcetimingworkerstart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_workerstart"></a></h4> 1178<div class="api_metadata"> 1179<span>Added in: v18.2.0</span> 1180</div> 1181<ul> 1182<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1183</ul> 1184<p>The high resolution millisecond timestamp at immediately before dispatching 1185the <code>fetch</code> request. If the resource is not intercepted by a worker the property 1186will always return 0.</p> 1187<h4><code>performanceResourceTiming.redirectStart</code><span><a class="mark" href="#performanceresourcetimingredirectstart" id="performanceresourcetimingredirectstart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_redirectstart"></a></h4> 1188<div class="api_metadata"> 1189<span>Added in: v18.2.0</span> 1190</div> 1191<ul> 1192<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1193</ul> 1194<p>The high resolution millisecond timestamp that represents the start time 1195of the fetch which initiates the redirect.</p> 1196<h4><code>performanceResourceTiming.redirectEnd</code><span><a class="mark" href="#performanceresourcetimingredirectend" id="performanceresourcetimingredirectend">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_redirectend"></a></h4> 1197<div class="api_metadata"> 1198<span>Added in: v18.2.0</span> 1199</div> 1200<ul> 1201<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1202</ul> 1203<p>The high resolution millisecond timestamp that will be created immediately after 1204receiving the last byte of the response of the last redirect.</p> 1205<h4><code>performanceResourceTiming.fetchStart</code><span><a class="mark" href="#performanceresourcetimingfetchstart" id="performanceresourcetimingfetchstart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_fetchstart"></a></h4> 1206<div class="api_metadata"> 1207<span>Added in: v18.2.0</span> 1208</div> 1209<ul> 1210<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1211</ul> 1212<p>The high resolution millisecond timestamp immediately before the Node.js starts 1213to fetch the resource.</p> 1214<h4><code>performanceResourceTiming.domainLookupStart</code><span><a class="mark" href="#performanceresourcetimingdomainlookupstart" id="performanceresourcetimingdomainlookupstart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_domainlookupstart"></a></h4> 1215<div class="api_metadata"> 1216<span>Added in: v18.2.0</span> 1217</div> 1218<ul> 1219<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1220</ul> 1221<p>The high resolution millisecond timestamp immediately before the Node.js starts 1222the domain name lookup for the resource.</p> 1223<h4><code>performanceResourceTiming.domainLookupEnd</code><span><a class="mark" href="#performanceresourcetimingdomainlookupend" id="performanceresourcetimingdomainlookupend">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_domainlookupend"></a></h4> 1224<div class="api_metadata"> 1225<span>Added in: v18.2.0</span> 1226</div> 1227<ul> 1228<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1229</ul> 1230<p>The high resolution millisecond timestamp representing the time immediately 1231after the Node.js finished the domain name lookup for the resource.</p> 1232<h4><code>performanceResourceTiming.connectStart</code><span><a class="mark" href="#performanceresourcetimingconnectstart" id="performanceresourcetimingconnectstart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_connectstart"></a></h4> 1233<div class="api_metadata"> 1234<span>Added in: v18.2.0</span> 1235</div> 1236<ul> 1237<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1238</ul> 1239<p>The high resolution millisecond timestamp representing the time immediately 1240before Node.js starts to establish the connection to the server to retrieve 1241the resource.</p> 1242<h4><code>performanceResourceTiming.connectEnd</code><span><a class="mark" href="#performanceresourcetimingconnectend" id="performanceresourcetimingconnectend">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_connectend"></a></h4> 1243<div class="api_metadata"> 1244<span>Added in: v18.2.0</span> 1245</div> 1246<ul> 1247<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1248</ul> 1249<p>The high resolution millisecond timestamp representing the time immediately 1250after Node.js finishes establishing the connection to the server to retrieve 1251the resource.</p> 1252<h4><code>performanceResourceTiming.secureConnectionStart</code><span><a class="mark" href="#performanceresourcetimingsecureconnectionstart" id="performanceresourcetimingsecureconnectionstart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_secureconnectionstart"></a></h4> 1253<div class="api_metadata"> 1254<span>Added in: v18.2.0</span> 1255</div> 1256<ul> 1257<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1258</ul> 1259<p>The high resolution millisecond timestamp representing the time immediately 1260before Node.js starts the handshake process to secure the current connection.</p> 1261<h4><code>performanceResourceTiming.requestStart</code><span><a class="mark" href="#performanceresourcetimingrequeststart" id="performanceresourcetimingrequeststart">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_requeststart"></a></h4> 1262<div class="api_metadata"> 1263<span>Added in: v18.2.0</span> 1264</div> 1265<ul> 1266<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1267</ul> 1268<p>The high resolution millisecond timestamp representing the time immediately 1269before Node.js receives the first byte of the response from the server.</p> 1270<h4><code>performanceResourceTiming.responseEnd</code><span><a class="mark" href="#performanceresourcetimingresponseend" id="performanceresourcetimingresponseend">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_responseend"></a></h4> 1271<div class="api_metadata"> 1272<span>Added in: v18.2.0</span> 1273</div> 1274<ul> 1275<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1276</ul> 1277<p>The high resolution millisecond timestamp representing the time immediately 1278after Node.js receives the last byte of the resource or immediately before 1279the transport connection is closed, whichever comes first.</p> 1280<h4><code>performanceResourceTiming.transferSize</code><span><a class="mark" href="#performanceresourcetimingtransfersize" id="performanceresourcetimingtransfersize">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_transfersize"></a></h4> 1281<div class="api_metadata"> 1282<span>Added in: v18.2.0</span> 1283</div> 1284<ul> 1285<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1286</ul> 1287<p>A number representing the size (in octets) of the fetched resource. The size 1288includes the response header fields plus the response payload body.</p> 1289<h4><code>performanceResourceTiming.encodedBodySize</code><span><a class="mark" href="#performanceresourcetimingencodedbodysize" id="performanceresourcetimingencodedbodysize">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_encodedbodysize"></a></h4> 1290<div class="api_metadata"> 1291<span>Added in: v18.2.0</span> 1292</div> 1293<ul> 1294<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1295</ul> 1296<p>A number representing the size (in octets) received from the fetch 1297(HTTP or cache), of the payload body, before removing any applied 1298content-codings.</p> 1299<h4><code>performanceResourceTiming.decodedBodySize</code><span><a class="mark" href="#performanceresourcetimingdecodedbodysize" id="performanceresourcetimingdecodedbodysize">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_decodedbodysize"></a></h4> 1300<div class="api_metadata"> 1301<span>Added in: v18.2.0</span> 1302</div> 1303<ul> 1304<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1305</ul> 1306<p>A number representing the size (in octets) received from the fetch 1307(HTTP or cache), of the message body, after removing any applied 1308content-codings.</p> 1309<h4><code>performanceResourceTiming.toJSON()</code><span><a class="mark" href="#performanceresourcetimingtojson" id="performanceresourcetimingtojson">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceresourcetiming_tojson"></a></h4> 1310<div class="api_metadata"> 1311<span>Added in: v18.2.0</span> 1312</div> 1313<p>Returns a <code>object</code> that is the JSON representation of the 1314<code>PerformanceResourceTiming</code> object</p> 1315</section><section><h3>Class: <code>perf_hooks.PerformanceObserver</code><span><a class="mark" href="#class-perf_hooksperformanceobserver" id="class-perf_hooksperformanceobserver">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_perf_hooks_performanceobserver"></a></h3> 1316<div class="api_metadata"> 1317<span>Added in: v8.5.0</span> 1318</div> 1319<h4><code>PerformanceObserver.supportedEntryTypes</code><span><a class="mark" href="#performanceobserversupportedentrytypes" id="performanceobserversupportedentrytypes">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceobserver_supportedentrytypes"></a></h4> 1320<div class="api_metadata"> 1321<span>Added in: v16.0.0</span> 1322</div> 1323<ul> 1324<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a></li> 1325</ul> 1326<p>Get supported types.</p> 1327<h4><code>new PerformanceObserver(callback)</code><span><a class="mark" href="#new-performanceobservercallback" id="new-performanceobservercallback">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_new_performanceobserver_callback"></a></h4> 1328<div class="api_metadata"> 1329<details class="changelog"><summary>History</summary> 1330<table> 1331<tbody><tr><th>Version</th><th>Changes</th></tr> 1332<tr><td>v18.0.0</td> 1333<td><p>Passing an invalid callback to the <code>callback</code> argument now throws <code>ERR_INVALID_ARG_TYPE</code> instead of <code>ERR_INVALID_CALLBACK</code>.</p></td></tr> 1334<tr><td>v8.5.0</td> 1335<td><p><span>Added in: v8.5.0</span></p></td></tr> 1336</tbody></table> 1337</details> 1338</div> 1339<ul> 1340<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type"><Function></a> 1341<ul> 1342<li><code>list</code> <a href="perf_hooks.html#class-performanceobserverentrylist" class="type"><PerformanceObserverEntryList></a></li> 1343<li><code>observer</code> <a href="perf_hooks.html#class-perf_hooksperformanceobserver" class="type"><PerformanceObserver></a></li> 1344</ul> 1345</li> 1346</ul> 1347<p><code>PerformanceObserver</code> objects provide notifications when new 1348<code>PerformanceEntry</code> instances have been added to the Performance Timeline.</p> 1349<pre><code class="language-js"><span class="hljs-keyword">const</span> { 1350 performance, 1351 <span class="hljs-title class_">PerformanceObserver</span>, 1352} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1353 1354<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">list, observer</span>) =></span> { 1355 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(list.<span class="hljs-title function_">getEntries</span>()); 1356 1357 performance.<span class="hljs-title function_">clearMarks</span>(); 1358 performance.<span class="hljs-title function_">clearMeasures</span>(); 1359 observer.<span class="hljs-title function_">disconnect</span>(); 1360}); 1361obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'mark'</span>], <span class="hljs-attr">buffered</span>: <span class="hljs-literal">true</span> }); 1362 1363performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>);</code> <button class="copy-button">copy</button></pre> 1364<p>Because <code>PerformanceObserver</code> instances introduce their own additional 1365performance overhead, instances should not be left subscribed to notifications 1366indefinitely. Users should disconnect observers as soon as they are no 1367longer needed.</p> 1368<p>The <code>callback</code> is invoked when a <code>PerformanceObserver</code> is 1369notified about new <code>PerformanceEntry</code> instances. The callback receives a 1370<code>PerformanceObserverEntryList</code> instance and a reference to the 1371<code>PerformanceObserver</code>.</p> 1372<h4><code>performanceObserver.disconnect()</code><span><a class="mark" href="#performanceobserverdisconnect" id="performanceobserverdisconnect">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceobserver_disconnect"></a></h4> 1373<div class="api_metadata"> 1374<span>Added in: v8.5.0</span> 1375</div> 1376<p>Disconnects the <code>PerformanceObserver</code> instance from all notifications.</p> 1377<h4><code>performanceObserver.observe(options)</code><span><a class="mark" href="#performanceobserverobserveoptions" id="performanceobserverobserveoptions">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceobserver_observe_options"></a></h4> 1378<div class="api_metadata"> 1379<details class="changelog"><summary>History</summary> 1380<table> 1381<tbody><tr><th>Version</th><th>Changes</th></tr> 1382<tr><td>v16.7.0</td> 1383<td><p>Updated to conform to Performance Timeline Level 2. The buffered option has been added back.</p></td></tr> 1384<tr><td>v16.0.0</td> 1385<td><p>Updated to conform to User Timing Level 3. The buffered option has been removed.</p></td></tr> 1386<tr><td>v8.5.0</td> 1387<td><p><span>Added in: v8.5.0</span></p></td></tr> 1388</tbody></table> 1389</details> 1390</div> 1391<ul> 1392<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 1393<ul> 1394<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a> A single <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry></a> type. Must not be given 1395if <code>entryTypes</code> is already specified.</li> 1396<li><code>entryTypes</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string[]></a> An array of strings identifying the types of 1397<a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry></a> instances the observer is interested in. If not 1398provided an error will be thrown.</li> 1399<li><code>buffered</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a> If true, the observer callback is called with a 1400list global <code>PerformanceEntry</code> buffered entries. If false, only 1401<code>PerformanceEntry</code>s created after the time point are sent to the 1402observer callback. <strong>Default:</strong> <code>false</code>.</li> 1403</ul> 1404</li> 1405</ul> 1406<p>Subscribes the <a href="perf_hooks.html#class-perf_hooksperformanceobserver" class="type"><PerformanceObserver></a> instance to notifications of new 1407<a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry></a> instances identified either by <code>options.entryTypes</code> 1408or <code>options.type</code>:</p> 1409<pre><code class="language-js"><span class="hljs-keyword">const</span> { 1410 performance, 1411 <span class="hljs-title class_">PerformanceObserver</span>, 1412} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1413 1414<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">list, observer</span>) =></span> { 1415 <span class="hljs-comment">// Called once asynchronously. `list` contains three items.</span> 1416}); 1417obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'mark'</span> }); 1418 1419<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> n = <span class="hljs-number">0</span>; n < <span class="hljs-number">3</span>; n++) 1420 performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">`test<span class="hljs-subst">${n}</span>`</span>);</code> <button class="copy-button">copy</button></pre> 1421</section><section><h3>Class: <code>PerformanceObserverEntryList</code><span><a class="mark" href="#class-performanceobserverentrylist" id="class-performanceobserverentrylist">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_performanceobserverentrylist"></a></h3> 1422<div class="api_metadata"> 1423<span>Added in: v8.5.0</span> 1424</div> 1425<p>The <code>PerformanceObserverEntryList</code> class is used to provide access to the 1426<code>PerformanceEntry</code> instances passed to a <code>PerformanceObserver</code>. 1427The constructor of this class is not exposed to users.</p> 1428<h4><code>performanceObserverEntryList.getEntries()</code><span><a class="mark" href="#performanceobserverentrylistgetentries" id="performanceobserverentrylistgetentries">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceobserverentrylist_getentries"></a></h4> 1429<div class="api_metadata"> 1430<span>Added in: v8.5.0</span> 1431</div> 1432<ul> 1433<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry[]></a></li> 1434</ul> 1435<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order 1436with respect to <code>performanceEntry.startTime</code>.</p> 1437<pre><code class="language-js"><span class="hljs-keyword">const</span> { 1438 performance, 1439 <span class="hljs-title class_">PerformanceObserver</span>, 1440} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1441 1442<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">perfObserverList, observer</span>) =></span> { 1443 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(perfObserverList.<span class="hljs-title function_">getEntries</span>()); 1444 <span class="hljs-comment">/** 1445 * [ 1446 * PerformanceEntry { 1447 * name: 'test', 1448 * entryType: 'mark', 1449 * startTime: 81.465639, 1450 * duration: 0 1451 * }, 1452 * PerformanceEntry { 1453 * name: 'meow', 1454 * entryType: 'mark', 1455 * startTime: 81.860064, 1456 * duration: 0 1457 * } 1458 * ] 1459 */</span> 1460 1461 performance.<span class="hljs-title function_">clearMarks</span>(); 1462 performance.<span class="hljs-title function_">clearMeasures</span>(); 1463 observer.<span class="hljs-title function_">disconnect</span>(); 1464}); 1465obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'mark'</span> }); 1466 1467performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>); 1468performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'meow'</span>);</code> <button class="copy-button">copy</button></pre> 1469<h4><code>performanceObserverEntryList.getEntriesByName(name[, type])</code><span><a class="mark" href="#performanceobserverentrylistgetentriesbynamename-type" id="performanceobserverentrylistgetentriesbynamename-type">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceobserverentrylist_getentriesbyname_name_type"></a></h4> 1470<div class="api_metadata"> 1471<span>Added in: v8.5.0</span> 1472</div> 1473<ul> 1474<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1475<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1476<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry[]></a></li> 1477</ul> 1478<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order 1479with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.name</code> is 1480equal to <code>name</code>, and optionally, whose <code>performanceEntry.entryType</code> is equal to 1481<code>type</code>.</p> 1482<pre><code class="language-js"><span class="hljs-keyword">const</span> { 1483 performance, 1484 <span class="hljs-title class_">PerformanceObserver</span>, 1485} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1486 1487<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">perfObserverList, observer</span>) =></span> { 1488 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(perfObserverList.<span class="hljs-title function_">getEntriesByName</span>(<span class="hljs-string">'meow'</span>)); 1489 <span class="hljs-comment">/** 1490 * [ 1491 * PerformanceEntry { 1492 * name: 'meow', 1493 * entryType: 'mark', 1494 * startTime: 98.545991, 1495 * duration: 0 1496 * } 1497 * ] 1498 */</span> 1499 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(perfObserverList.<span class="hljs-title function_">getEntriesByName</span>(<span class="hljs-string">'nope'</span>)); <span class="hljs-comment">// []</span> 1500 1501 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(perfObserverList.<span class="hljs-title function_">getEntriesByName</span>(<span class="hljs-string">'test'</span>, <span class="hljs-string">'mark'</span>)); 1502 <span class="hljs-comment">/** 1503 * [ 1504 * PerformanceEntry { 1505 * name: 'test', 1506 * entryType: 'mark', 1507 * startTime: 63.518931, 1508 * duration: 0 1509 * } 1510 * ] 1511 */</span> 1512 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(perfObserverList.<span class="hljs-title function_">getEntriesByName</span>(<span class="hljs-string">'test'</span>, <span class="hljs-string">'measure'</span>)); <span class="hljs-comment">// []</span> 1513 1514 performance.<span class="hljs-title function_">clearMarks</span>(); 1515 performance.<span class="hljs-title function_">clearMeasures</span>(); 1516 observer.<span class="hljs-title function_">disconnect</span>(); 1517}); 1518obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'mark'</span>, <span class="hljs-string">'measure'</span>] }); 1519 1520performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>); 1521performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'meow'</span>);</code> <button class="copy-button">copy</button></pre> 1522<h4><code>performanceObserverEntryList.getEntriesByType(type)</code><span><a class="mark" href="#performanceobserverentrylistgetentriesbytypetype" id="performanceobserverentrylistgetentriesbytypetype">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_performanceobserverentrylist_getentriesbytype_type"></a></h4> 1523<div class="api_metadata"> 1524<span>Added in: v8.5.0</span> 1525</div> 1526<ul> 1527<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type"><string></a></li> 1528<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type"><PerformanceEntry[]></a></li> 1529</ul> 1530<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order 1531with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.entryType</code> 1532is equal to <code>type</code>.</p> 1533<pre><code class="language-js"><span class="hljs-keyword">const</span> { 1534 performance, 1535 <span class="hljs-title class_">PerformanceObserver</span>, 1536} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1537 1538<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">perfObserverList, observer</span>) =></span> { 1539 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(perfObserverList.<span class="hljs-title function_">getEntriesByType</span>(<span class="hljs-string">'mark'</span>)); 1540 <span class="hljs-comment">/** 1541 * [ 1542 * PerformanceEntry { 1543 * name: 'test', 1544 * entryType: 'mark', 1545 * startTime: 55.897834, 1546 * duration: 0 1547 * }, 1548 * PerformanceEntry { 1549 * name: 'meow', 1550 * entryType: 'mark', 1551 * startTime: 56.350146, 1552 * duration: 0 1553 * } 1554 * ] 1555 */</span> 1556 performance.<span class="hljs-title function_">clearMarks</span>(); 1557 performance.<span class="hljs-title function_">clearMeasures</span>(); 1558 observer.<span class="hljs-title function_">disconnect</span>(); 1559}); 1560obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'mark'</span> }); 1561 1562performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>); 1563performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'meow'</span>);</code> <button class="copy-button">copy</button></pre> 1564</section><section><h3><code>perf_hooks.createHistogram([options])</code><span><a class="mark" href="#perf_hookscreatehistogramoptions" id="perf_hookscreatehistogramoptions">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_perf_hooks_createhistogram_options"></a></h3> 1565<div class="api_metadata"> 1566<span>Added in: v15.9.0, v14.18.0</span> 1567</div> 1568<ul> 1569<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 1570<ul> 1571<li><code>lowest</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a> The lowest discernible value. Must be an integer 1572value greater than 0. <strong>Default:</strong> <code>1</code>.</li> 1573<li><code>highest</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a> The highest recordable value. Must be an integer 1574value that is equal to or greater than two times <code>lowest</code>. 1575<strong>Default:</strong> <code>Number.MAX_SAFE_INTEGER</code>.</li> 1576<li><code>figures</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The number of accuracy digits. Must be a number between 1577<code>1</code> and <code>5</code>. <strong>Default:</strong> <code>3</code>.</li> 1578</ul> 1579</li> 1580<li>Returns <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type"><RecordableHistogram></a></li> 1581</ul> 1582<p>Returns a <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type"><RecordableHistogram></a>.</p> 1583</section><section><h3><code>perf_hooks.monitorEventLoopDelay([options])</code><span><a class="mark" href="#perf_hooksmonitoreventloopdelayoptions" id="perf_hooksmonitoreventloopdelayoptions">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_perf_hooks_monitoreventloopdelay_options"></a></h3> 1584<div class="api_metadata"> 1585<span>Added in: v11.10.0</span> 1586</div> 1587<ul> 1588<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type"><Object></a> 1589<ul> 1590<li><code>resolution</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> The sampling rate in milliseconds. Must be greater 1591than zero. <strong>Default:</strong> <code>10</code>.</li> 1592</ul> 1593</li> 1594<li>Returns: <a href="perf_hooks.html#class-intervalhistogram-extends-histogram" class="type"><IntervalHistogram></a></li> 1595</ul> 1596<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p> 1597<p>Creates an <code>IntervalHistogram</code> object that samples and reports the event loop 1598delay over time. The delays will be reported in nanoseconds.</p> 1599<p>Using a timer to detect approximate event loop delay works because the 1600execution of timers is tied specifically to the lifecycle of the libuv 1601event loop. That is, a delay in the loop will cause a delay in the execution 1602of the timer, and those delays are specifically what this API is intended to 1603detect.</p> 1604<pre><code class="language-js"><span class="hljs-keyword">const</span> { monitorEventLoopDelay } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1605<span class="hljs-keyword">const</span> h = <span class="hljs-title function_">monitorEventLoopDelay</span>({ <span class="hljs-attr">resolution</span>: <span class="hljs-number">20</span> }); 1606h.<span class="hljs-title function_">enable</span>(); 1607<span class="hljs-comment">// Do something.</span> 1608h.<span class="hljs-title function_">disable</span>(); 1609<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">min</span>); 1610<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">max</span>); 1611<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">mean</span>); 1612<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">stddev</span>); 1613<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">percentiles</span>); 1614<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-title function_">percentile</span>(<span class="hljs-number">50</span>)); 1615<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-title function_">percentile</span>(<span class="hljs-number">99</span>));</code> <button class="copy-button">copy</button></pre> 1616</section><section><h3>Class: <code>Histogram</code><span><a class="mark" href="#class-histogram" id="class-histogram">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_histogram"></a></h3> 1617<div class="api_metadata"> 1618<span>Added in: v11.10.0</span> 1619</div> 1620<h4><code>histogram.count</code><span><a class="mark" href="#histogramcount" id="histogramcount">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_count"></a></h4> 1621<div class="api_metadata"> 1622<span>Added in: v17.4.0, v16.14.0</span> 1623</div> 1624<ul> 1625<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1626</ul> 1627<p>The number of samples recorded by the histogram.</p> 1628<h4><code>histogram.countBigInt</code><span><a class="mark" href="#histogramcountbigint" id="histogramcountbigint">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_countbigint"></a></h4> 1629<div class="api_metadata"> 1630<span>Added in: v17.4.0, v16.14.0</span> 1631</div> 1632<ul> 1633<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a></li> 1634</ul> 1635<p>The number of samples recorded by the histogram.</p> 1636<h4><code>histogram.exceeds</code><span><a class="mark" href="#histogramexceeds" id="histogramexceeds">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_exceeds"></a></h4> 1637<div class="api_metadata"> 1638<span>Added in: v11.10.0</span> 1639</div> 1640<ul> 1641<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1642</ul> 1643<p>The number of times the event loop delay exceeded the maximum 1 hour event 1644loop delay threshold.</p> 1645<h4><code>histogram.exceedsBigInt</code><span><a class="mark" href="#histogramexceedsbigint" id="histogramexceedsbigint">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_exceedsbigint"></a></h4> 1646<div class="api_metadata"> 1647<span>Added in: v17.4.0, v16.14.0</span> 1648</div> 1649<ul> 1650<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a></li> 1651</ul> 1652<p>The number of times the event loop delay exceeded the maximum 1 hour event 1653loop delay threshold.</p> 1654<h4><code>histogram.max</code><span><a class="mark" href="#histogrammax" id="histogrammax">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_max"></a></h4> 1655<div class="api_metadata"> 1656<span>Added in: v11.10.0</span> 1657</div> 1658<ul> 1659<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1660</ul> 1661<p>The maximum recorded event loop delay.</p> 1662<h4><code>histogram.maxBigInt</code><span><a class="mark" href="#histogrammaxbigint" id="histogrammaxbigint">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_maxbigint"></a></h4> 1663<div class="api_metadata"> 1664<span>Added in: v17.4.0, v16.14.0</span> 1665</div> 1666<ul> 1667<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a></li> 1668</ul> 1669<p>The maximum recorded event loop delay.</p> 1670<h4><code>histogram.mean</code><span><a class="mark" href="#histogrammean" id="histogrammean">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_mean"></a></h4> 1671<div class="api_metadata"> 1672<span>Added in: v11.10.0</span> 1673</div> 1674<ul> 1675<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1676</ul> 1677<p>The mean of the recorded event loop delays.</p> 1678<h4><code>histogram.min</code><span><a class="mark" href="#histogrammin" id="histogrammin">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_min"></a></h4> 1679<div class="api_metadata"> 1680<span>Added in: v11.10.0</span> 1681</div> 1682<ul> 1683<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1684</ul> 1685<p>The minimum recorded event loop delay.</p> 1686<h4><code>histogram.minBigInt</code><span><a class="mark" href="#histogramminbigint" id="histogramminbigint">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_minbigint"></a></h4> 1687<div class="api_metadata"> 1688<span>Added in: v17.4.0, v16.14.0</span> 1689</div> 1690<ul> 1691<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a></li> 1692</ul> 1693<p>The minimum recorded event loop delay.</p> 1694<h4><code>histogram.percentile(percentile)</code><span><a class="mark" href="#histogrampercentilepercentile" id="histogrampercentilepercentile">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_percentile_percentile"></a></h4> 1695<div class="api_metadata"> 1696<span>Added in: v11.10.0</span> 1697</div> 1698<ul> 1699<li><code>percentile</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A percentile value in the range (0, 100].</li> 1700<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1701</ul> 1702<p>Returns the value at the given percentile.</p> 1703<h4><code>histogram.percentileBigInt(percentile)</code><span><a class="mark" href="#histogrampercentilebigintpercentile" id="histogrampercentilebigintpercentile">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_percentilebigint_percentile"></a></h4> 1704<div class="api_metadata"> 1705<span>Added in: v17.4.0, v16.14.0</span> 1706</div> 1707<ul> 1708<li><code>percentile</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> A percentile value in the range (0, 100].</li> 1709<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a></li> 1710</ul> 1711<p>Returns the value at the given percentile.</p> 1712<h4><code>histogram.percentiles</code><span><a class="mark" href="#histogrampercentiles" id="histogrampercentiles">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_percentiles"></a></h4> 1713<div class="api_metadata"> 1714<span>Added in: v11.10.0</span> 1715</div> 1716<ul> 1717<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map" class="type"><Map></a></li> 1718</ul> 1719<p>Returns a <code>Map</code> object detailing the accumulated percentile distribution.</p> 1720<h4><code>histogram.percentilesBigInt</code><span><a class="mark" href="#histogrampercentilesbigint" id="histogrampercentilesbigint">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_percentilesbigint"></a></h4> 1721<div class="api_metadata"> 1722<span>Added in: v17.4.0, v16.14.0</span> 1723</div> 1724<ul> 1725<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map" class="type"><Map></a></li> 1726</ul> 1727<p>Returns a <code>Map</code> object detailing the accumulated percentile distribution.</p> 1728<h4><code>histogram.reset()</code><span><a class="mark" href="#histogramreset" id="histogramreset">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_reset"></a></h4> 1729<div class="api_metadata"> 1730<span>Added in: v11.10.0</span> 1731</div> 1732<p>Resets the collected histogram data.</p> 1733<h4><code>histogram.stddev</code><span><a class="mark" href="#histogramstddev" id="histogramstddev">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_stddev"></a></h4> 1734<div class="api_metadata"> 1735<span>Added in: v11.10.0</span> 1736</div> 1737<ul> 1738<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a></li> 1739</ul> 1740<p>The standard deviation of the recorded event loop delays.</p> 1741</section><section><h3>Class: <code>IntervalHistogram extends Histogram</code><span><a class="mark" href="#class-intervalhistogram-extends-histogram" id="class-intervalhistogram-extends-histogram">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_intervalhistogram_extends_histogram"></a></h3> 1742<p>A <code>Histogram</code> that is periodically updated on a given interval.</p> 1743<h4><code>histogram.disable()</code><span><a class="mark" href="#histogramdisable" id="histogramdisable">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_disable"></a></h4> 1744<div class="api_metadata"> 1745<span>Added in: v11.10.0</span> 1746</div> 1747<ul> 1748<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> 1749</ul> 1750<p>Disables the update interval timer. Returns <code>true</code> if the timer was 1751stopped, <code>false</code> if it was already stopped.</p> 1752<h4><code>histogram.enable()</code><span><a class="mark" href="#histogramenable" id="histogramenable">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_enable"></a></h4> 1753<div class="api_metadata"> 1754<span>Added in: v11.10.0</span> 1755</div> 1756<ul> 1757<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type"><boolean></a></li> 1758</ul> 1759<p>Enables the update interval timer. Returns <code>true</code> if the timer was 1760started, <code>false</code> if it was already started.</p> 1761<h4>Cloning an <code>IntervalHistogram</code><span><a class="mark" href="#cloning-an-intervalhistogram" id="cloning-an-intervalhistogram">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_cloning_an_intervalhistogram"></a></h4> 1762<p><a href="perf_hooks.html#class-intervalhistogram-extends-histogram" class="type"><IntervalHistogram></a> instances can be cloned via <a href="worker_threads.html#class-messageport" class="type"><MessagePort></a>. On the receiving 1763end, the histogram is cloned as a plain <a href="perf_hooks.html#class-histogram" class="type"><Histogram></a> object that does not 1764implement the <code>enable()</code> and <code>disable()</code> methods.</p> 1765</section><section><h3>Class: <code>RecordableHistogram extends Histogram</code><span><a class="mark" href="#class-recordablehistogram-extends-histogram" id="class-recordablehistogram-extends-histogram">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_class_recordablehistogram_extends_histogram"></a></h3> 1766<div class="api_metadata"> 1767<span>Added in: v15.9.0, v14.18.0</span> 1768</div> 1769<h4><code>histogram.add(other)</code><span><a class="mark" href="#histogramaddother" id="histogramaddother">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_add_other"></a></h4> 1770<div class="api_metadata"> 1771<span>Added in: v17.4.0, v16.14.0</span> 1772</div> 1773<ul> 1774<li><code>other</code> <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type"><RecordableHistogram></a></li> 1775</ul> 1776<p>Adds the values from <code>other</code> to this histogram.</p> 1777<h4><code>histogram.record(val)</code><span><a class="mark" href="#histogramrecordval" id="histogramrecordval">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_record_val"></a></h4> 1778<div class="api_metadata"> 1779<span>Added in: v15.9.0, v14.18.0</span> 1780</div> 1781<ul> 1782<li><code>val</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type"><number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type"><bigint></a> The amount to record in the histogram.</li> 1783</ul> 1784<h4><code>histogram.recordDelta()</code><span><a class="mark" href="#histogramrecorddelta" id="histogramrecorddelta">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_histogram_recorddelta"></a></h4> 1785<div class="api_metadata"> 1786<span>Added in: v15.9.0, v14.18.0</span> 1787</div> 1788<p>Calculates the amount of time (in nanoseconds) that has passed since the 1789previous call to <code>recordDelta()</code> and records that amount in the histogram.</p> 1790</section><section><h3>Examples<span><a class="mark" href="#examples" id="examples">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_examples"></a></h3> 1791<h4>Measuring the duration of async operations<span><a class="mark" href="#measuring-the-duration-of-async-operations" id="measuring-the-duration-of-async-operations">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_measuring_the_duration_of_async_operations"></a></h4> 1792<p>The following example uses the <a href="async_hooks.html">Async Hooks</a> and Performance APIs to measure 1793the actual duration of a Timeout operation (including the amount of time it took 1794to execute the callback).</p> 1795<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>; 1796<span class="hljs-keyword">const</span> async_hooks = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:async_hooks'</span>); 1797<span class="hljs-keyword">const</span> { 1798 performance, 1799 <span class="hljs-title class_">PerformanceObserver</span>, 1800} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1801 1802<span class="hljs-keyword">const</span> set = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Set</span>(); 1803<span class="hljs-keyword">const</span> hook = async_hooks.<span class="hljs-title function_">createHook</span>({ 1804 <span class="hljs-title function_">init</span>(<span class="hljs-params">id, type</span>) { 1805 <span class="hljs-keyword">if</span> (type === <span class="hljs-string">'Timeout'</span>) { 1806 performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Init`</span>); 1807 set.<span class="hljs-title function_">add</span>(id); 1808 } 1809 }, 1810 <span class="hljs-title function_">destroy</span>(<span class="hljs-params">id</span>) { 1811 <span class="hljs-keyword">if</span> (set.<span class="hljs-title function_">has</span>(id)) { 1812 set.<span class="hljs-title function_">delete</span>(id); 1813 performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Destroy`</span>); 1814 performance.<span class="hljs-title function_">measure</span>(<span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>`</span>, 1815 <span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Init`</span>, 1816 <span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Destroy`</span>); 1817 } 1818 }, 1819}); 1820hook.<span class="hljs-title function_">enable</span>(); 1821 1822<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">list, observer</span>) =></span> { 1823 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(list.<span class="hljs-title function_">getEntries</span>()[<span class="hljs-number">0</span>]); 1824 performance.<span class="hljs-title function_">clearMarks</span>(); 1825 performance.<span class="hljs-title function_">clearMeasures</span>(); 1826 observer.<span class="hljs-title function_">disconnect</span>(); 1827}); 1828obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'measure'</span>], <span class="hljs-attr">buffered</span>: <span class="hljs-literal">true</span> }); 1829 1830<span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =></span> {}, <span class="hljs-number">1000</span>);</code> <button class="copy-button">copy</button></pre> 1831<h4>Measuring how long it takes to load dependencies<span><a class="mark" href="#measuring-how-long-it-takes-to-load-dependencies" id="measuring-how-long-it-takes-to-load-dependencies">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_measuring_how_long_it_takes_to_load_dependencies"></a></h4> 1832<p>The following example measures the duration of <code>require()</code> operations to load 1833dependencies:</p> 1834<!-- eslint-disable no-global-assign --> 1835<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>; 1836<span class="hljs-keyword">const</span> { 1837 performance, 1838 <span class="hljs-title class_">PerformanceObserver</span>, 1839} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1840<span class="hljs-keyword">const</span> mod = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:module'</span>); 1841 1842<span class="hljs-comment">// Monkey patch the require function</span> 1843mod.<span class="hljs-property">Module</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>.<span class="hljs-property">require</span> = 1844 performance.<span class="hljs-title function_">timerify</span>(mod.<span class="hljs-property">Module</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>.<span class="hljs-property">require</span>); 1845<span class="hljs-built_in">require</span> = performance.<span class="hljs-title function_">timerify</span>(<span class="hljs-built_in">require</span>); 1846 1847<span class="hljs-comment">// Activate the observer</span> 1848<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">list</span>) =></span> { 1849 <span class="hljs-keyword">const</span> entries = list.<span class="hljs-title function_">getEntries</span>(); 1850 entries.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">entry</span>) =></span> { 1851 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`require('<span class="hljs-subst">${entry[<span class="hljs-number">0</span>]}</span>')`</span>, entry.<span class="hljs-property">duration</span>); 1852 }); 1853 performance.<span class="hljs-title function_">clearMarks</span>(); 1854 performance.<span class="hljs-title function_">clearMeasures</span>(); 1855 obs.<span class="hljs-title function_">disconnect</span>(); 1856}); 1857obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'function'</span>], <span class="hljs-attr">buffered</span>: <span class="hljs-literal">true</span> }); 1858 1859<span class="hljs-built_in">require</span>(<span class="hljs-string">'some-module'</span>);</code> <button class="copy-button">copy</button></pre> 1860<h4>Measuring how long one HTTP round-trip takes<span><a class="mark" href="#measuring-how-long-one-http-round-trip-takes" id="measuring-how-long-one-http-round-trip-takes">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_measuring_how_long_one_http_round_trip_takes"></a></h4> 1861<p>The following example is used to trace the time spent by HTTP client 1862(<code>OutgoingMessage</code>) and HTTP request (<code>IncomingMessage</code>). For HTTP client, 1863it means the time interval between starting the request and receiving the 1864response, and for HTTP request, it means the time interval between receiving 1865the request and sending the response:</p> 1866<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>; 1867<span class="hljs-keyword">const</span> { <span class="hljs-title class_">PerformanceObserver</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1868<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:http'</span>); 1869 1870<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">items</span>) =></span> { 1871 items.<span class="hljs-title function_">getEntries</span>().<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">item</span>) =></span> { 1872 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(item); 1873 }); 1874}); 1875 1876obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'http'</span>] }); 1877 1878<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">PORT</span> = <span class="hljs-number">8080</span>; 1879 1880http.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">req, res</span>) =></span> { 1881 res.<span class="hljs-title function_">end</span>(<span class="hljs-string">'ok'</span>); 1882}).<span class="hljs-title function_">listen</span>(<span class="hljs-variable constant_">PORT</span>, <span class="hljs-function">() =></span> { 1883 http.<span class="hljs-title function_">get</span>(<span class="hljs-string">`http://127.0.0.1:<span class="hljs-subst">${PORT}</span>`</span>); 1884});</code> <button class="copy-button">copy</button></pre> 1885<h4>Measuring how long the <code>net.connect</code> (only for TCP) takes when the connection is successful<span><a class="mark" href="#measuring-how-long-the-netconnect-only-for-tcp-takes-when-the-connection-is-successful" id="measuring-how-long-the-netconnect-only-for-tcp-takes-when-the-connection-is-successful">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_measuring_how_long_the_net_connect_only_for_tcp_takes_when_the_connection_is_successful"></a></h4> 1886<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>; 1887<span class="hljs-keyword">const</span> { <span class="hljs-title class_">PerformanceObserver</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1888<span class="hljs-keyword">const</span> net = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:net'</span>); 1889<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">items</span>) =></span> { 1890 items.<span class="hljs-title function_">getEntries</span>().<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">item</span>) =></span> { 1891 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(item); 1892 }); 1893}); 1894obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'net'</span>] }); 1895<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">PORT</span> = <span class="hljs-number">8080</span>; 1896net.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">socket</span>) =></span> { 1897 socket.<span class="hljs-title function_">destroy</span>(); 1898}).<span class="hljs-title function_">listen</span>(<span class="hljs-variable constant_">PORT</span>, <span class="hljs-function">() =></span> { 1899 net.<span class="hljs-title function_">connect</span>(<span class="hljs-variable constant_">PORT</span>); 1900});</code> <button class="copy-button">copy</button></pre> 1901<h4>Measuring how long the DNS takes when the request is successful<span><a class="mark" href="#measuring-how-long-the-dns-takes-when-the-request-is-successful" id="measuring-how-long-the-dns-takes-when-the-request-is-successful">#</a></span><a aria-hidden="true" class="legacy" id="perf_hooks_measuring_how_long_the_dns_takes_when_the_request_is_successful"></a></h4> 1902<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>; 1903<span class="hljs-keyword">const</span> { <span class="hljs-title class_">PerformanceObserver</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>); 1904<span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>); 1905<span class="hljs-keyword">const</span> obs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">PerformanceObserver</span>(<span class="hljs-function">(<span class="hljs-params">items</span>) =></span> { 1906 items.<span class="hljs-title function_">getEntries</span>().<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">item</span>) =></span> { 1907 <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(item); 1908 }); 1909}); 1910obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'dns'</span>] }); 1911dns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'localhost'</span>, <span class="hljs-function">() =></span> {}); 1912dns.<span class="hljs-property">promises</span>.<span class="hljs-title function_">resolve</span>(<span class="hljs-string">'localhost'</span>);</code> <button class="copy-button">copy</button></pre></section> 1913 <!-- API END --> 1914 </div> 1915 </div> 1916 </div> 1917</body> 1918</html> 1919