• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.18.2">
7  <title>Performance measurement APIs | Node.js v18.18.2 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.18.2 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.18.2</li>
115
116    <li class="picker-header">
117      <a href="#">
118        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</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">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</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">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
349        Other versions
350      </a>
351      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v20.x/api/perf_hooks.html">20.x</a></li>
352<li><a href="https://nodejs.org/docs/latest-v19.x/api/perf_hooks.html">19.x</a></li>
353<li><a href="https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html">18.x <b>LTS</b></a></li>
354<li><a href="https://nodejs.org/docs/latest-v17.x/api/perf_hooks.html">17.x</a></li>
355<li><a href="https://nodejs.org/docs/latest-v16.x/api/perf_hooks.html">16.x</a></li>
356<li><a href="https://nodejs.org/docs/latest-v15.x/api/perf_hooks.html">15.x</a></li>
357<li><a href="https://nodejs.org/docs/latest-v14.x/api/perf_hooks.html">14.x</a></li>
358<li><a href="https://nodejs.org/docs/latest-v13.x/api/perf_hooks.html">13.x</a></li>
359<li><a href="https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html">12.x</a></li>
360<li><a href="https://nodejs.org/docs/latest-v11.x/api/perf_hooks.html">11.x</a></li>
361<li><a href="https://nodejs.org/docs/latest-v10.x/api/perf_hooks.html">10.x</a></li>
362<li><a href="https://nodejs.org/docs/latest-v9.x/api/perf_hooks.html">9.x</a></li>
363<li><a href="https://nodejs.org/docs/latest-v8.x/api/perf_hooks.html">8.x</a></li></ol></div>
364    </li>
365
366            <li class="picker-header">
367              <a href="#">
368                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
369                Options
370              </a>
371
372              <div class="picker">
373                <ul>
374                  <li>
375                    <a href="all.html">View on single page</a>
376                  </li>
377                  <li>
378                    <a href="perf_hooks.json">View as JSON</a>
379                  </li>
380                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/perf_hooks.md">Edit on GitHub</a></li>
381                </ul>
382              </div>
383            </li>
384          </ul>
385        </div>
386        <hr>
387      </header>
388
389      <details id="toc" open><summary>Table of contents</summary><ul>
390<li><span class="stability_2"><a href="#performance-measurement-apis">Performance measurement APIs</a></span>
391<ul>
392<li><a href="#perf_hooksperformance"><code>perf_hooks.performance</code></a>
393<ul>
394<li><a href="#performanceclearmarksname"><code>performance.clearMarks([name])</code></a></li>
395<li><a href="#performanceclearmeasuresname"><code>performance.clearMeasures([name])</code></a></li>
396<li><a href="#performanceclearresourcetimingsname"><code>performance.clearResourceTimings([name])</code></a></li>
397<li><a href="#performanceeventlooputilizationutilization1-utilization2"><code>performance.eventLoopUtilization([utilization1[, utilization2]])</code></a></li>
398<li><a href="#performancegetentries"><code>performance.getEntries()</code></a></li>
399<li><a href="#performancegetentriesbynamename-type"><code>performance.getEntriesByName(name[, type])</code></a></li>
400<li><a href="#performancegetentriesbytypetype"><code>performance.getEntriesByType(type)</code></a></li>
401<li><a href="#performancemarkname-options"><code>performance.mark([name[, options]])</code></a></li>
402<li><a href="#performancemarkresourcetimingtiminginfo-requestedurl-initiatortype-global-cachemode"><code>performance.markResourceTiming(timingInfo, requestedUrl, initiatorType, global, cacheMode)</code></a></li>
403<li><a href="#performancemeasurename-startmarkoroptions-endmark"><code>performance.measure(name[, startMarkOrOptions[, endMark]])</code></a></li>
404<li><a href="#performancenodetiming"><code>performance.nodeTiming</code></a></li>
405<li><a href="#performancenow"><code>performance.now()</code></a></li>
406<li><a href="#performancesetresourcetimingbuffersizemaxsize"><code>performance.setResourceTimingBufferSize(maxSize)</code></a></li>
407<li><a href="#performancetimeorigin"><code>performance.timeOrigin</code></a></li>
408<li><a href="#performancetimerifyfn-options"><code>performance.timerify(fn[, options])</code></a></li>
409<li><a href="#performancetojson"><code>performance.toJSON()</code></a>
410<ul>
411<li><a href="#event-resourcetimingbufferfull">Event: <code>'resourcetimingbufferfull'</code></a></li>
412</ul>
413</li>
414</ul>
415</li>
416<li><a href="#class-performanceentry">Class: <code>PerformanceEntry</code></a>
417<ul>
418<li><a href="#performanceentrydetail"><code>performanceEntry.detail</code></a></li>
419<li><a href="#performanceentryduration"><code>performanceEntry.duration</code></a></li>
420<li><a href="#performanceentryentrytype"><code>performanceEntry.entryType</code></a></li>
421<li><a href="#performanceentryflags"><code>performanceEntry.flags</code></a></li>
422<li><a href="#performanceentryname"><code>performanceEntry.name</code></a></li>
423<li><a href="#performanceentrykind"><code>performanceEntry.kind</code></a></li>
424<li><a href="#performanceentrystarttime"><code>performanceEntry.startTime</code></a></li>
425<li><a href="#garbage-collection-gc-details">Garbage Collection ('gc') Details</a></li>
426<li><a href="#http-http-details">HTTP ('http') Details</a></li>
427<li><a href="#http2-http2-details">HTTP/2 ('http2') Details</a></li>
428<li><a href="#timerify-function-details">Timerify ('function') Details</a></li>
429<li><a href="#net-net-details">Net ('net') Details</a></li>
430<li><a href="#dns-dns-details">DNS ('dns') Details</a></li>
431</ul>
432</li>
433<li><a href="#class-performancenodetiming">Class: <code>PerformanceNodeTiming</code></a>
434<ul>
435<li><a href="#performancenodetimingbootstrapcomplete"><code>performanceNodeTiming.bootstrapComplete</code></a></li>
436<li><a href="#performancenodetimingenvironment"><code>performanceNodeTiming.environment</code></a></li>
437<li><a href="#performancenodetimingidletime"><code>performanceNodeTiming.idleTime</code></a></li>
438<li><a href="#performancenodetimingloopexit"><code>performanceNodeTiming.loopExit</code></a></li>
439<li><a href="#performancenodetimingloopstart"><code>performanceNodeTiming.loopStart</code></a></li>
440<li><a href="#performancenodetimingnodestart"><code>performanceNodeTiming.nodeStart</code></a></li>
441<li><a href="#performancenodetimingv8start"><code>performanceNodeTiming.v8Start</code></a></li>
442</ul>
443</li>
444<li><a href="#class-performanceresourcetiming">Class: <code>PerformanceResourceTiming</code></a>
445<ul>
446<li><a href="#performanceresourcetimingworkerstart"><code>performanceResourceTiming.workerStart</code></a></li>
447<li><a href="#performanceresourcetimingredirectstart"><code>performanceResourceTiming.redirectStart</code></a></li>
448<li><a href="#performanceresourcetimingredirectend"><code>performanceResourceTiming.redirectEnd</code></a></li>
449<li><a href="#performanceresourcetimingfetchstart"><code>performanceResourceTiming.fetchStart</code></a></li>
450<li><a href="#performanceresourcetimingdomainlookupstart"><code>performanceResourceTiming.domainLookupStart</code></a></li>
451<li><a href="#performanceresourcetimingdomainlookupend"><code>performanceResourceTiming.domainLookupEnd</code></a></li>
452<li><a href="#performanceresourcetimingconnectstart"><code>performanceResourceTiming.connectStart</code></a></li>
453<li><a href="#performanceresourcetimingconnectend"><code>performanceResourceTiming.connectEnd</code></a></li>
454<li><a href="#performanceresourcetimingsecureconnectionstart"><code>performanceResourceTiming.secureConnectionStart</code></a></li>
455<li><a href="#performanceresourcetimingrequeststart"><code>performanceResourceTiming.requestStart</code></a></li>
456<li><a href="#performanceresourcetimingresponseend"><code>performanceResourceTiming.responseEnd</code></a></li>
457<li><a href="#performanceresourcetimingtransfersize"><code>performanceResourceTiming.transferSize</code></a></li>
458<li><a href="#performanceresourcetimingencodedbodysize"><code>performanceResourceTiming.encodedBodySize</code></a></li>
459<li><a href="#performanceresourcetimingdecodedbodysize"><code>performanceResourceTiming.decodedBodySize</code></a></li>
460<li><a href="#performanceresourcetimingtojson"><code>performanceResourceTiming.toJSON()</code></a></li>
461</ul>
462</li>
463<li><a href="#class-perf_hooksperformanceobserver">Class: <code>perf_hooks.PerformanceObserver</code></a>
464<ul>
465<li><a href="#performanceobserversupportedentrytypes"><code>PerformanceObserver.supportedEntryTypes</code></a></li>
466<li><a href="#new-performanceobservercallback"><code>new PerformanceObserver(callback)</code></a></li>
467<li><a href="#performanceobserverdisconnect"><code>performanceObserver.disconnect()</code></a></li>
468<li><a href="#performanceobserverobserveoptions"><code>performanceObserver.observe(options)</code></a></li>
469</ul>
470</li>
471<li><a href="#class-performanceobserverentrylist">Class: <code>PerformanceObserverEntryList</code></a>
472<ul>
473<li><a href="#performanceobserverentrylistgetentries"><code>performanceObserverEntryList.getEntries()</code></a></li>
474<li><a href="#performanceobserverentrylistgetentriesbynamename-type"><code>performanceObserverEntryList.getEntriesByName(name[, type])</code></a></li>
475<li><a href="#performanceobserverentrylistgetentriesbytypetype"><code>performanceObserverEntryList.getEntriesByType(type)</code></a></li>
476</ul>
477</li>
478<li><a href="#perf_hookscreatehistogramoptions"><code>perf_hooks.createHistogram([options])</code></a></li>
479<li><a href="#perf_hooksmonitoreventloopdelayoptions"><code>perf_hooks.monitorEventLoopDelay([options])</code></a></li>
480<li><a href="#class-histogram">Class: <code>Histogram</code></a>
481<ul>
482<li><a href="#histogramcount"><code>histogram.count</code></a></li>
483<li><a href="#histogramcountbigint"><code>histogram.countBigInt</code></a></li>
484<li><a href="#histogramexceeds"><code>histogram.exceeds</code></a></li>
485<li><a href="#histogramexceedsbigint"><code>histogram.exceedsBigInt</code></a></li>
486<li><a href="#histogrammax"><code>histogram.max</code></a></li>
487<li><a href="#histogrammaxbigint"><code>histogram.maxBigInt</code></a></li>
488<li><a href="#histogrammean"><code>histogram.mean</code></a></li>
489<li><a href="#histogrammin"><code>histogram.min</code></a></li>
490<li><a href="#histogramminbigint"><code>histogram.minBigInt</code></a></li>
491<li><a href="#histogrampercentilepercentile"><code>histogram.percentile(percentile)</code></a></li>
492<li><a href="#histogrampercentilebigintpercentile"><code>histogram.percentileBigInt(percentile)</code></a></li>
493<li><a href="#histogrampercentiles"><code>histogram.percentiles</code></a></li>
494<li><a href="#histogrampercentilesbigint"><code>histogram.percentilesBigInt</code></a></li>
495<li><a href="#histogramreset"><code>histogram.reset()</code></a></li>
496<li><a href="#histogramstddev"><code>histogram.stddev</code></a></li>
497</ul>
498</li>
499<li><a href="#class-intervalhistogram-extends-histogram">Class: <code>IntervalHistogram extends Histogram</code></a>
500<ul>
501<li><a href="#histogramdisable"><code>histogram.disable()</code></a></li>
502<li><a href="#histogramenable"><code>histogram.enable()</code></a></li>
503<li><a href="#cloning-an-intervalhistogram">Cloning an <code>IntervalHistogram</code></a></li>
504</ul>
505</li>
506<li><a href="#class-recordablehistogram-extends-histogram">Class: <code>RecordableHistogram extends Histogram</code></a>
507<ul>
508<li><a href="#histogramaddother"><code>histogram.add(other)</code></a></li>
509<li><a href="#histogramrecordval"><code>histogram.record(val)</code></a></li>
510<li><a href="#histogramrecorddelta"><code>histogram.recordDelta()</code></a></li>
511</ul>
512</li>
513<li><a href="#examples">Examples</a>
514<ul>
515<li><a href="#measuring-the-duration-of-async-operations">Measuring the duration of async operations</a></li>
516<li><a href="#measuring-how-long-it-takes-to-load-dependencies">Measuring how long it takes to load dependencies</a></li>
517<li><a href="#measuring-how-long-one-http-round-trip-takes">Measuring how long one HTTP round-trip takes</a></li>
518<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>
519<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>
520</ul>
521</li>
522</ul>
523</li>
524</ul></details>
525
526      <div id="apicontent">
527        <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>
528
529<p></p><div class="api_stability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</div><p></p>
530<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.18.2/lib/perf_hooks.js">lib/perf_hooks.js</a></p>
531<p>This module provides an implementation of a subset of the W3C
532<a href="https://w3c.github.io/perf-timing-primer/">Web Performance APIs</a> as well as additional APIs for
533Node.js-specific performance measurements.</p>
534<p>Node.js supports the following <a href="https://w3c.github.io/perf-timing-primer/">Web Performance APIs</a>:</p>
535<ul>
536<li><a href="https://www.w3.org/TR/hr-time-2">High Resolution Time</a></li>
537<li><a href="https://w3c.github.io/performance-timeline/">Performance Timeline</a></li>
538<li><a href="https://www.w3.org/TR/user-timing/">User Timing</a></li>
539<li><a href="https://www.w3.org/TR/resource-timing-2/">Resource Timing</a></li>
540</ul>
541<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>);
542
543<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> {
544  <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>);
545  performance.<span class="hljs-title function_">clearMarks</span>();
546});
547obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'measure'</span> });
548performance.<span class="hljs-title function_">measure</span>(<span class="hljs-string">'Start to Now'</span>);
549
550performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'A'</span>);
551<span class="hljs-title function_">doSomeLongRunningProcess</span>(<span class="hljs-function">() =></span> {
552  performance.<span class="hljs-title function_">measure</span>(<span class="hljs-string">'A to Now'</span>, <span class="hljs-string">'A'</span>);
553
554  performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'B'</span>);
555  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>);
556});</code> <button class="copy-button">copy</button></pre>
557<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>
558<div class="api_metadata">
559<span>Added in: v8.5.0</span>
560</div>
561<p>An object that can be used to collect performance metrics from the current
562Node.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>
563<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>
564<div class="api_metadata">
565<span>Added in: v8.5.0</span>
566</div>
567<ul>
568<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
569</ul>
570<p>If <code>name</code> is not provided, removes all <code>PerformanceMark</code> objects from the
571Performance Timeline. If <code>name</code> is provided, removes only the named mark.</p>
572<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>
573<div class="api_metadata">
574<span>Added in: v16.7.0</span>
575</div>
576<ul>
577<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
578</ul>
579<p>If <code>name</code> is not provided, removes all <code>PerformanceMeasure</code> objects from the
580Performance Timeline. If <code>name</code> is provided, removes only the named measure.</p>
581<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>
582<div class="api_metadata">
583<span>Added in: v18.2.0</span>
584</div>
585<ul>
586<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
587</ul>
588<p>If <code>name</code> is not provided, removes all <code>PerformanceResourceTiming</code> objects from
589the Resource Timeline. If <code>name</code> is provided, removes only the named resource.</p>
590<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>
591<div class="api_metadata">
592<span>Added in: v14.10.0, v12.19.0</span>
593</div>
594<ul>
595<li><code>utilization1</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> The result of a previous call to
596<code>eventLoopUtilization()</code>.</li>
597<li><code>utilization2</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> The result of a previous call to
598<code>eventLoopUtilization()</code> prior to <code>utilization1</code>.</li>
599<li>Returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
600<ul>
601<li><code>idle</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
602<li><code>active</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
603<li><code>utilization</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
604</ul>
605</li>
606</ul>
607<p>The <code>eventLoopUtilization()</code> method returns an object that contains the
608cumulative duration of time the event loop has been both idle and active as a
609high resolution milliseconds timer. The <code>utilization</code> value is the calculated
610Event Loop Utilization (ELU).</p>
611<p>If bootstrapping has not yet finished on the main thread the properties have
612the value of <code>0</code>. The ELU is immediately available on <a href="worker_threads.html#worker-threads">Worker threads</a> since
613bootstrap happens within the event loop.</p>
614<p>Both <code>utilization1</code> and <code>utilization2</code> are optional parameters.</p>
615<p>If <code>utilization1</code> is passed, then the delta between the current call's <code>active</code>
616and <code>idle</code> times, as well as the corresponding <code>utilization</code> value are
617calculated and returned (similar to <a href="process.html#processhrtimetime"><code>process.hrtime()</code></a>).</p>
618<p>If <code>utilization1</code> and <code>utilization2</code> are both passed, then the delta is
619calculated between the two arguments. This is a convenience option because,
620unlike <a href="process.html#processhrtimetime"><code>process.hrtime()</code></a>, calculating the ELU is more complex than a
621single subtraction.</p>
622<p>ELU is similar to CPU utilization, except that it only measures event loop
623statistics and not CPU usage. It represents the percentage of time the event
624loop has spent outside the event loop's event provider (e.g. <code>epoll_wait</code>).
625No other CPU idle time is taken into consideration. The following is an example
626of how a mostly idle process will have a high ELU.</p>
627<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>;
628<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>;
629<span class="hljs-keyword">const</span> { spawnSync } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:child_process'</span>);
630
631<span class="hljs-title function_">setImmediate</span>(<span class="hljs-function">() =></span> {
632  <span class="hljs-keyword">const</span> elu = <span class="hljs-title function_">eventLoopUtilization</span>();
633  <span class="hljs-title function_">spawnSync</span>(<span class="hljs-string">'sleep'</span>, [<span class="hljs-string">'5'</span>]);
634  <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>);
635});</code> <button class="copy-button">copy</button></pre>
636<p>Although the CPU is mostly idle while running this script, the value of
637<code>utilization</code> is <code>1</code>. This is because the call to
638<a href="child_process.html#child_processspawnsynccommand-args-options"><code>child_process.spawnSync()</code></a> blocks the event loop from proceeding.</p>
639<p>Passing in a user-defined object instead of the result of a previous call to
640<code>eventLoopUtilization()</code> will lead to undefined behavior. The return values
641are not guaranteed to reflect any correct state of the event loop.</p>
642<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>
643<div class="api_metadata">
644<span>Added in: v16.7.0</span>
645</div>
646<ul>
647<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry[]></a></li>
648</ul>
649<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order with
650respect to <code>performanceEntry.startTime</code>. If you are only interested in
651performance entries of certain types or that have certain names, see
652<code>performance.getEntriesByType()</code> and <code>performance.getEntriesByName()</code>.</p>
653<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>
654<div class="api_metadata">
655<span>Added in: v16.7.0</span>
656</div>
657<ul>
658<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
659<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
660<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry[]></a></li>
661</ul>
662<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order
663with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.name</code> is
664equal to <code>name</code>, and optionally, whose <code>performanceEntry.entryType</code> is equal to
665<code>type</code>.</p>
666<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>
667<div class="api_metadata">
668<span>Added in: v16.7.0</span>
669</div>
670<ul>
671<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
672<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry[]></a></li>
673</ul>
674<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order
675with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.entryType</code>
676is equal to <code>type</code>.</p>
677<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>
678<div class="api_metadata">
679<details class="changelog"><summary>History</summary>
680<table>
681<tbody><tr><th>Version</th><th>Changes</th></tr>
682<tr><td>v16.0.0</td>
683<td><p>Updated to conform to the User Timing Level 3 specification.</p></td></tr>
684<tr><td>v8.5.0</td>
685<td><p><span>Added in: v8.5.0</span></p></td></tr>
686</tbody></table>
687</details>
688</div>
689<ul>
690<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
691<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
692<ul>
693<li><code>detail</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Additional optional detail to include with the mark.</li>
694<li><code>startTime</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> An optional timestamp to be used as the mark time.
695<strong>Default</strong>: <code>performance.now()</code>.</li>
696</ul>
697</li>
698</ul>
699<p>Creates a new <code>PerformanceMark</code> entry in the Performance Timeline. A
700<code>PerformanceMark</code> is a subclass of <code>PerformanceEntry</code> whose
701<code>performanceEntry.entryType</code> is always <code>'mark'</code>, and whose
702<code>performanceEntry.duration</code> is always <code>0</code>. Performance marks are used
703to mark specific significant moments in the Performance Timeline.</p>
704<p>The created <code>PerformanceMark</code> entry is put in the global Performance Timeline
705and can be queried with <code>performance.getEntries</code>,
706<code>performance.getEntriesByName</code>, and <code>performance.getEntriesByType</code>. When the
707observation is performed, the entries should be cleared from the global
708Performance Timeline manually with <code>performance.clearMarks</code>.</p>
709<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>
710<div class="api_metadata">
711<span>Added in: v18.2.0</span>
712</div>
713<ul>
714<li><code>timingInfo</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> <a href="https://fetch.spec.whatwg.org/#fetch-timing-info">Fetch Timing Info</a></li>
715<li><code>requestedUrl</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The resource url</li>
716<li><code>initiatorType</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The initiator name, e.g: 'fetch'</li>
717<li><code>global</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a></li>
718<li><code>cacheMode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> The cache mode must be an empty string ('') or 'local'</li>
719</ul>
720<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p>
721<p>Creates a new <code>PerformanceResourceTiming</code> entry in the Resource Timeline. A
722<code>PerformanceResourceTiming</code> is a subclass of <code>PerformanceEntry</code> whose
723<code>performanceEntry.entryType</code> is always <code>'resource'</code>. Performance resources
724are used to mark moments in the Resource Timeline.</p>
725<p>The created <code>PerformanceMark</code> entry is put in the global Resource Timeline
726and can be queried with <code>performance.getEntries</code>,
727<code>performance.getEntriesByName</code>, and <code>performance.getEntriesByType</code>. When the
728observation is performed, the entries should be cleared from the global
729Performance Timeline manually with <code>performance.clearResourceTimings</code>.</p>
730<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>
731<div class="api_metadata">
732<details class="changelog"><summary>History</summary>
733<table>
734<tbody><tr><th>Version</th><th>Changes</th></tr>
735<tr><td>v16.0.0</td>
736<td><p>Updated to conform to the User Timing Level 3 specification.</p></td></tr>
737<tr><td>v13.13.0, v12.16.3</td>
738<td><p>Make <code>startMark</code> and <code>endMark</code> parameters optional.</p></td></tr>
739<tr><td>v8.5.0</td>
740<td><p><span>Added in: v8.5.0</span></p></td></tr>
741</tbody></table>
742</details>
743</div>
744<ul>
745<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
746<li><code>startMarkOrOptions</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Optional.
747<ul>
748<li><code>detail</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> Additional optional detail to include with the measure.</li>
749<li><code>duration</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> Duration between start and end times.</li>
750<li><code>end</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Timestamp to be used as the end time, or a string
751identifying a previously recorded mark.</li>
752<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Timestamp to be used as the start time, or a string
753identifying a previously recorded mark.</li>
754</ul>
755</li>
756<li><code>endMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Optional. Must be omitted if <code>startMarkOrOptions</code> is an
757<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>.</li>
758</ul>
759<p>Creates a new <code>PerformanceMeasure</code> entry in the Performance Timeline. A
760<code>PerformanceMeasure</code> is a subclass of <code>PerformanceEntry</code> whose
761<code>performanceEntry.entryType</code> is always <code>'measure'</code>, and whose
762<code>performanceEntry.duration</code> measures the number of milliseconds elapsed since
763<code>startMark</code> and <code>endMark</code>.</p>
764<p>The <code>startMark</code> argument may identify any <em>existing</em> <code>PerformanceMark</code> in the
765Performance Timeline, or <em>may</em> identify any of the timestamp properties
766provided by the <code>PerformanceNodeTiming</code> class. If the named <code>startMark</code> does
767not exist, an error is thrown.</p>
768<p>The optional <code>endMark</code> argument must identify any <em>existing</em> <code>PerformanceMark</code>
769in the Performance Timeline or any of the timestamp properties provided by the
770<code>PerformanceNodeTiming</code> class. <code>endMark</code> will be <code>performance.now()</code>
771if no parameter is passed, otherwise if the named <code>endMark</code> does not exist, an
772error will be thrown.</p>
773<p>The created <code>PerformanceMeasure</code> entry is put in the global Performance Timeline
774and can be queried with <code>performance.getEntries</code>,
775<code>performance.getEntriesByName</code>, and <code>performance.getEntriesByType</code>. When the
776observation is performed, the entries should be cleared from the global
777Performance Timeline manually with <code>performance.clearMeasures</code>.</p>
778<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>
779<div class="api_metadata">
780<span>Added in: v8.5.0</span>
781</div>
782<ul>
783<li><a href="perf_hooks.html#class-performancenodetiming" class="type">&#x3C;PerformanceNodeTiming></a></li>
784</ul>
785<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p>
786<p>An instance of the <code>PerformanceNodeTiming</code> class that provides performance
787metrics for specific Node.js operational milestones.</p>
788<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>
789<div class="api_metadata">
790<span>Added in: v8.5.0</span>
791</div>
792<ul>
793<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
794</ul>
795<p>Returns the current high resolution millisecond timestamp, where 0 represents
796the start of the current <code>node</code> process.</p>
797<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>
798<div class="api_metadata">
799<span>Added in: v18.8.0</span>
800</div>
801<p>Sets the global performance resource timing buffer size to the specified number
802of "resource" type performance entry objects.</p>
803<p>By default the max buffer size is set to 250.</p>
804<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>
805<div class="api_metadata">
806<span>Added in: v8.5.0</span>
807</div>
808<ul>
809<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
810</ul>
811<p>The <a href="https://w3c.github.io/hr-time/#dom-performance-timeorigin"><code>timeOrigin</code></a> specifies the high resolution millisecond timestamp at
812which the current <code>node</code> process began, measured in Unix time.</p>
813<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>
814<div class="api_metadata">
815<details class="changelog"><summary>History</summary>
816<table>
817<tbody><tr><th>Version</th><th>Changes</th></tr>
818<tr><td>v16.0.0</td>
819<td><p>Added the histogram option.</p></td></tr>
820<tr><td>v16.0.0</td>
821<td><p>Re-implemented to use pure-JavaScript and the ability to time async functions.</p></td></tr>
822<tr><td>v8.5.0</td>
823<td><p><span>Added in: v8.5.0</span></p></td></tr>
824</tbody></table>
825</details>
826</div>
827<ul>
828<li><code>fn</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
829<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
830<ul>
831<li><code>histogram</code> <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type">&#x3C;RecordableHistogram></a> A histogram object created using
832<code>perf_hooks.createHistogram()</code> that will record runtime durations in
833nanoseconds.</li>
834</ul>
835</li>
836</ul>
837<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p>
838<p>Wraps a function within a new function that measures the running time of the
839wrapped function. A <code>PerformanceObserver</code> must be subscribed to the <code>'function'</code>
840event type in order for the timing details to be accessed.</p>
841<pre><code class="language-js"><span class="hljs-keyword">const</span> {
842  performance,
843  <span class="hljs-title class_">PerformanceObserver</span>,
844} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
845
846<span class="hljs-keyword">function</span> <span class="hljs-title function_">someFunction</span>(<span class="hljs-params"></span>) {
847  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'hello world'</span>);
848}
849
850<span class="hljs-keyword">const</span> wrapped = performance.<span class="hljs-title function_">timerify</span>(someFunction);
851
852<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> {
853  <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>);
854
855  performance.<span class="hljs-title function_">clearMarks</span>();
856  performance.<span class="hljs-title function_">clearMeasures</span>();
857  obs.<span class="hljs-title function_">disconnect</span>();
858});
859obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'function'</span>] });
860
861<span class="hljs-comment">// A performance timeline entry will be created</span>
862<span class="hljs-title function_">wrapped</span>();</code> <button class="copy-button">copy</button></pre>
863<p>If the wrapped function returns a promise, a finally handler will be attached
864to the promise and the duration will be reported once the finally handler is
865invoked.</p>
866<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>
867<div class="api_metadata">
868<span>Added in: v16.1.0</span>
869</div>
870<p>An object which is JSON representation of the <code>performance</code> object. It
871is similar to <a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance/toJSON"><code>window.performance.toJSON</code></a> in browsers.</p>
872<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>
873<div class="api_metadata">
874<span>Added in: v18.8.0</span>
875</div>
876<p>The <code>'resourcetimingbufferfull'</code> event is fired when the global performance
877resource timing buffer is full. Adjust resource timing buffer size with
878<code>performance.setResourceTimingBufferSize()</code> or clear the buffer with
879<code>performance.clearResourceTimings()</code> in the event listener to allow
880more entries to be added to the performance timeline buffer.</p>
881</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>
882<div class="api_metadata">
883<span>Added in: v8.5.0</span>
884</div>
885<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>
886<div class="api_metadata">
887<span>Added in: v16.0.0</span>
888</div>
889<ul>
890<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
891</ul>
892<p>Additional detail specific to the <code>entryType</code>.</p>
893<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>
894<div class="api_metadata">
895<span>Added in: v8.5.0</span>
896</div>
897<ul>
898<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
899</ul>
900<p>The total number of milliseconds elapsed for this entry. This value will not
901be meaningful for all Performance Entry types.</p>
902<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>
903<div class="api_metadata">
904<span>Added in: v8.5.0</span>
905</div>
906<ul>
907<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
908</ul>
909<p>The type of the performance entry. It may be one of:</p>
910<ul>
911<li><code>'node'</code> (Node.js only)</li>
912<li><code>'mark'</code> (available on the Web)</li>
913<li><code>'measure'</code> (available on the Web)</li>
914<li><code>'gc'</code> (Node.js only)</li>
915<li><code>'function'</code> (Node.js only)</li>
916<li><code>'http2'</code> (Node.js only)</li>
917<li><code>'http'</code> (Node.js only)</li>
918</ul>
919<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>
920<div class="api_metadata">
921<details class="changelog"><summary>History</summary>
922<table>
923<tbody><tr><th>Version</th><th>Changes</th></tr>
924<tr><td>v16.0.0</td>
925<td><p>Runtime deprecated. Now moved to the detail property when entryType is 'gc'.</p></td></tr>
926<tr><td>v13.9.0, v12.17.0</td>
927<td><p><span>Added in: v13.9.0, v12.17.0</span></p></td></tr>
928</tbody></table>
929</details>
930</div>
931<ul>
932<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
933</ul>
934<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p>
935<p>When <code>performanceEntry.entryType</code> is equal to <code>'gc'</code>, the <code>performance.flags</code>
936property contains additional information about garbage collection operation.
937The value may be one of:</p>
938<ul>
939<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO</code></li>
940<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED</code></li>
941<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED</code></li>
942<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING</code></li>
943<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE</code></li>
944<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY</code></li>
945<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE</code></li>
946</ul>
947<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>
948<div class="api_metadata">
949<span>Added in: v8.5.0</span>
950</div>
951<ul>
952<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
953</ul>
954<p>The name of the performance entry.</p>
955<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>
956<div class="api_metadata">
957<details class="changelog"><summary>History</summary>
958<table>
959<tbody><tr><th>Version</th><th>Changes</th></tr>
960<tr><td>v16.0.0</td>
961<td><p>Runtime deprecated. Now moved to the detail property when entryType is 'gc'.</p></td></tr>
962<tr><td>v8.5.0</td>
963<td><p><span>Added in: v8.5.0</span></p></td></tr>
964</tbody></table>
965</details>
966</div>
967<ul>
968<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
969</ul>
970<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p>
971<p>When <code>performanceEntry.entryType</code> is equal to <code>'gc'</code>, the <code>performance.kind</code>
972property identifies the type of garbage collection operation that occurred.
973The value may be one of:</p>
974<ul>
975<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR</code></li>
976<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR</code></li>
977<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL</code></li>
978<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB</code></li>
979</ul>
980<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>
981<div class="api_metadata">
982<span>Added in: v8.5.0</span>
983</div>
984<ul>
985<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
986</ul>
987<p>The high resolution millisecond timestamp marking the starting time of the
988Performance Entry.</p>
989<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>
990<p>When <code>performanceEntry.type</code> is equal to <code>'gc'</code>, the <code>performanceEntry.detail</code>
991property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> with two properties:</p>
992<ul>
993<li><code>kind</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> One of:
994<ul>
995<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR</code></li>
996<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR</code></li>
997<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL</code></li>
998<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB</code></li>
999</ul>
1000</li>
1001<li><code>flags</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> One of:
1002<ul>
1003<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_NO</code></li>
1004<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED</code></li>
1005<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_FORCED</code></li>
1006<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING</code></li>
1007<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE</code></li>
1008<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY</code></li>
1009<li><code>perf_hooks.constants.NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE</code></li>
1010</ul>
1011</li>
1012</ul>
1013<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>
1014<p>When <code>performanceEntry.type</code> is equal to <code>'http'</code>, the <code>performanceEntry.detail</code>
1015property will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> containing additional information.</p>
1016<p>If <code>performanceEntry.name</code> is equal to <code>HttpClient</code>, the <code>detail</code>
1017will contain the following properties: <code>req</code>, <code>res</code>. And the <code>req</code> property
1018will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> containing <code>method</code>, <code>url</code>, <code>headers</code>, the <code>res</code> property
1019will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> containing <code>statusCode</code>, <code>statusMessage</code>, <code>headers</code>.</p>
1020<p>If <code>performanceEntry.name</code> is equal to <code>HttpRequest</code>, the <code>detail</code>
1021will contain the following properties: <code>req</code>, <code>res</code>. And the <code>req</code> property
1022will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> containing <code>method</code>, <code>url</code>, <code>headers</code>, the <code>res</code> property
1023will be an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> containing <code>statusCode</code>, <code>statusMessage</code>, <code>headers</code>.</p>
1024<p>This could add additional memory overhead and should only be used for
1025diagnostic purposes, not left turned on in production by default.</p>
1026<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>
1027<p>When <code>performanceEntry.type</code> is equal to <code>'http2'</code>, the
1028<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">&#x3C;Object></a> containing
1029additional performance information.</p>
1030<p>If <code>performanceEntry.name</code> is equal to <code>Http2Stream</code>, the <code>detail</code>
1031will contain the following properties:</p>
1032<ul>
1033<li><code>bytesRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of <code>DATA</code> frame bytes received for this
1034<code>Http2Stream</code>.</li>
1035<li><code>bytesWritten</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of <code>DATA</code> frame bytes sent for this
1036<code>Http2Stream</code>.</li>
1037<li><code>id</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The identifier of the associated <code>Http2Stream</code></li>
1038<li><code>timeToFirstByte</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of milliseconds elapsed between the
1039<code>PerformanceEntry</code> <code>startTime</code> and the reception of the first <code>DATA</code> frame.</li>
1040<li><code>timeToFirstByteSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of milliseconds elapsed between
1041the <code>PerformanceEntry</code> <code>startTime</code> and sending of the first <code>DATA</code> frame.</li>
1042<li><code>timeToFirstHeader</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of milliseconds elapsed between the
1043<code>PerformanceEntry</code> <code>startTime</code> and the reception of the first header.</li>
1044</ul>
1045<p>If <code>performanceEntry.name</code> is equal to <code>Http2Session</code>, the <code>detail</code> will
1046contain the following properties:</p>
1047<ul>
1048<li><code>bytesRead</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of bytes received for this <code>Http2Session</code>.</li>
1049<li><code>bytesWritten</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of bytes sent for this <code>Http2Session</code>.</li>
1050<li><code>framesReceived</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of HTTP/2 frames received by the
1051<code>Http2Session</code>.</li>
1052<li><code>framesSent</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of HTTP/2 frames sent by the <code>Http2Session</code>.</li>
1053<li><code>maxConcurrentStreams</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The maximum number of streams concurrently
1054open during the lifetime of the <code>Http2Session</code>.</li>
1055<li><code>pingRTT</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of milliseconds elapsed since the transmission
1056of a <code>PING</code> frame and the reception of its acknowledgment. Only present if
1057a <code>PING</code> frame has been sent on the <code>Http2Session</code>.</li>
1058<li><code>streamAverageDuration</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The average duration (in milliseconds) for
1059all <code>Http2Stream</code> instances.</li>
1060<li><code>streamCount</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of <code>Http2Stream</code> instances processed by
1061the <code>Http2Session</code>.</li>
1062<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Either <code>'server'</code> or <code>'client'</code> to identify the type of
1063<code>Http2Session</code>.</li>
1064</ul>
1065<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>
1066<p>When <code>performanceEntry.type</code> is equal to <code>'function'</code>, the
1067<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">&#x3C;Array></a> listing
1068the input arguments to the timed function.</p>
1069<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>
1070<p>When <code>performanceEntry.type</code> is equal to <code>'net'</code>, the
1071<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">&#x3C;Object></a> containing
1072additional information.</p>
1073<p>If <code>performanceEntry.name</code> is equal to <code>connect</code>, the <code>detail</code>
1074will contain the following properties: <code>host</code>, <code>port</code>.</p>
1075<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>
1076<p>When <code>performanceEntry.type</code> is equal to <code>'dns'</code>, the
1077<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">&#x3C;Object></a> containing
1078additional information.</p>
1079<p>If <code>performanceEntry.name</code> is equal to <code>lookup</code>, the <code>detail</code>
1080will contain the following properties: <code>hostname</code>, <code>family</code>, <code>hints</code>, <code>verbatim</code>,
1081<code>addresses</code>.</p>
1082<p>If <code>performanceEntry.name</code> is equal to <code>lookupService</code>, the <code>detail</code> will
1083contain the following properties: <code>host</code>, <code>port</code>, <code>hostname</code>, <code>service</code>.</p>
1084<p>If <code>performanceEntry.name</code> is equal to <code>queryxxx</code> or <code>getHostByAddr</code>, the <code>detail</code> will
1085contain the following properties: <code>host</code>, <code>ttl</code>, <code>result</code>. The value of <code>result</code> is
1086same as the result of <code>queryxxx</code> or <code>getHostByAddr</code>.</p>
1087</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>
1088<div class="api_metadata">
1089<span>Added in: v8.5.0</span>
1090</div>
1091<ul>
1092<li>Extends: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry></a></li>
1093</ul>
1094<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p>
1095<p>Provides timing details for Node.js itself. The constructor of this class
1096is not exposed to users.</p>
1097<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>
1098<div class="api_metadata">
1099<span>Added in: v8.5.0</span>
1100</div>
1101<ul>
1102<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1103</ul>
1104<p>The high resolution millisecond timestamp at which the Node.js process
1105completed bootstrapping. If bootstrapping has not yet finished, the property
1106has the value of -1.</p>
1107<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>
1108<div class="api_metadata">
1109<span>Added in: v8.5.0</span>
1110</div>
1111<ul>
1112<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1113</ul>
1114<p>The high resolution millisecond timestamp at which the Node.js environment was
1115initialized.</p>
1116<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>
1117<div class="api_metadata">
1118<span>Added in: v14.10.0, v12.19.0</span>
1119</div>
1120<ul>
1121<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1122</ul>
1123<p>The high resolution millisecond timestamp of the amount of time the event loop
1124has been idle within the event loop's event provider (e.g. <code>epoll_wait</code>). This
1125does not take CPU usage into consideration. If the event loop has not yet
1126started (e.g., in the first tick of the main script), the property has the
1127value of 0.</p>
1128<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>
1129<div class="api_metadata">
1130<span>Added in: v8.5.0</span>
1131</div>
1132<ul>
1133<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1134</ul>
1135<p>The high resolution millisecond timestamp at which the Node.js event loop
1136exited. If the event loop has not yet exited, the property has the value of -1.
1137It 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>
1138<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>
1139<div class="api_metadata">
1140<span>Added in: v8.5.0</span>
1141</div>
1142<ul>
1143<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1144</ul>
1145<p>The high resolution millisecond timestamp at which the Node.js event loop
1146started. If the event loop has not yet started (e.g., in the first tick of the
1147main script), the property has the value of -1.</p>
1148<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>
1149<div class="api_metadata">
1150<span>Added in: v8.5.0</span>
1151</div>
1152<ul>
1153<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1154</ul>
1155<p>The high resolution millisecond timestamp at which the Node.js process was
1156initialized.</p>
1157<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>
1158<div class="api_metadata">
1159<span>Added in: v8.5.0</span>
1160</div>
1161<ul>
1162<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1163</ul>
1164<p>The high resolution millisecond timestamp at which the V8 platform was
1165initialized.</p>
1166</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>
1167<div class="api_metadata">
1168<span>Added in: v18.2.0</span>
1169</div>
1170<ul>
1171<li>Extends: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry></a></li>
1172</ul>
1173<p>Provides detailed network timing data regarding the loading of an application's
1174resources.</p>
1175<p>The constructor of this class is not exposed to users directly.</p>
1176<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>
1177<div class="api_metadata">
1178<span>Added in: v18.2.0</span>
1179</div>
1180<ul>
1181<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1182</ul>
1183<p>The high resolution millisecond timestamp at immediately before dispatching
1184the <code>fetch</code> request. If the resource is not intercepted by a worker the property
1185will always return 0.</p>
1186<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>
1187<div class="api_metadata">
1188<span>Added in: v18.2.0</span>
1189</div>
1190<ul>
1191<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1192</ul>
1193<p>The high resolution millisecond timestamp that represents the start time
1194of the fetch which initiates the redirect.</p>
1195<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>
1196<div class="api_metadata">
1197<span>Added in: v18.2.0</span>
1198</div>
1199<ul>
1200<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1201</ul>
1202<p>The high resolution millisecond timestamp that will be created immediately after
1203receiving the last byte of the response of the last redirect.</p>
1204<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>
1205<div class="api_metadata">
1206<span>Added in: v18.2.0</span>
1207</div>
1208<ul>
1209<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1210</ul>
1211<p>The high resolution millisecond timestamp immediately before the Node.js starts
1212to fetch the resource.</p>
1213<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>
1214<div class="api_metadata">
1215<span>Added in: v18.2.0</span>
1216</div>
1217<ul>
1218<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1219</ul>
1220<p>The high resolution millisecond timestamp immediately before the Node.js starts
1221the domain name lookup for the resource.</p>
1222<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>
1223<div class="api_metadata">
1224<span>Added in: v18.2.0</span>
1225</div>
1226<ul>
1227<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1228</ul>
1229<p>The high resolution millisecond timestamp representing the time immediately
1230after the Node.js finished the domain name lookup for the resource.</p>
1231<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>
1232<div class="api_metadata">
1233<span>Added in: v18.2.0</span>
1234</div>
1235<ul>
1236<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1237</ul>
1238<p>The high resolution millisecond timestamp representing the time immediately
1239before Node.js starts to establish the connection to the server to retrieve
1240the resource.</p>
1241<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>
1242<div class="api_metadata">
1243<span>Added in: v18.2.0</span>
1244</div>
1245<ul>
1246<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1247</ul>
1248<p>The high resolution millisecond timestamp representing the time immediately
1249after Node.js finishes establishing the connection to the server to retrieve
1250the resource.</p>
1251<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>
1252<div class="api_metadata">
1253<span>Added in: v18.2.0</span>
1254</div>
1255<ul>
1256<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1257</ul>
1258<p>The high resolution millisecond timestamp representing the time immediately
1259before Node.js starts the handshake process to secure the current connection.</p>
1260<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>
1261<div class="api_metadata">
1262<span>Added in: v18.2.0</span>
1263</div>
1264<ul>
1265<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1266</ul>
1267<p>The high resolution millisecond timestamp representing the time immediately
1268before Node.js receives the first byte of the response from the server.</p>
1269<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>
1270<div class="api_metadata">
1271<span>Added in: v18.2.0</span>
1272</div>
1273<ul>
1274<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1275</ul>
1276<p>The high resolution millisecond timestamp representing the time immediately
1277after Node.js receives the last byte of the resource or immediately before
1278the transport connection is closed, whichever comes first.</p>
1279<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>
1280<div class="api_metadata">
1281<span>Added in: v18.2.0</span>
1282</div>
1283<ul>
1284<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1285</ul>
1286<p>A number representing the size (in octets) of the fetched resource. The size
1287includes the response header fields plus the response payload body.</p>
1288<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>
1289<div class="api_metadata">
1290<span>Added in: v18.2.0</span>
1291</div>
1292<ul>
1293<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1294</ul>
1295<p>A number representing the size (in octets) received from the fetch
1296(HTTP or cache), of the payload body, before removing any applied
1297content-codings.</p>
1298<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>
1299<div class="api_metadata">
1300<span>Added in: v18.2.0</span>
1301</div>
1302<ul>
1303<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1304</ul>
1305<p>A number representing the size (in octets) received from the fetch
1306(HTTP or cache), of the message body, after removing any applied
1307content-codings.</p>
1308<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>
1309<div class="api_metadata">
1310<span>Added in: v18.2.0</span>
1311</div>
1312<p>Returns a <code>object</code> that is the JSON representation of the
1313<code>PerformanceResourceTiming</code> object</p>
1314</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>
1315<div class="api_metadata">
1316<span>Added in: v8.5.0</span>
1317</div>
1318<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>
1319<div class="api_metadata">
1320<span>Added in: v16.0.0</span>
1321</div>
1322<ul>
1323<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a></li>
1324</ul>
1325<p>Get supported types.</p>
1326<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>
1327<div class="api_metadata">
1328<details class="changelog"><summary>History</summary>
1329<table>
1330<tbody><tr><th>Version</th><th>Changes</th></tr>
1331<tr><td>v18.0.0</td>
1332<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>
1333<tr><td>v8.5.0</td>
1334<td><p><span>Added in: v8.5.0</span></p></td></tr>
1335</tbody></table>
1336</details>
1337</div>
1338<ul>
1339<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
1340<ul>
1341<li><code>list</code> <a href="perf_hooks.html#class-performanceobserverentrylist" class="type">&#x3C;PerformanceObserverEntryList></a></li>
1342<li><code>observer</code> <a href="perf_hooks.html#class-perf_hooksperformanceobserver" class="type">&#x3C;PerformanceObserver></a></li>
1343</ul>
1344</li>
1345</ul>
1346<p><code>PerformanceObserver</code> objects provide notifications when new
1347<code>PerformanceEntry</code> instances have been added to the Performance Timeline.</p>
1348<pre><code class="language-js"><span class="hljs-keyword">const</span> {
1349  performance,
1350  <span class="hljs-title class_">PerformanceObserver</span>,
1351} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
1352
1353<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> {
1354  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(list.<span class="hljs-title function_">getEntries</span>());
1355
1356  performance.<span class="hljs-title function_">clearMarks</span>();
1357  performance.<span class="hljs-title function_">clearMeasures</span>();
1358  observer.<span class="hljs-title function_">disconnect</span>();
1359});
1360obs.<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> });
1361
1362performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>);</code> <button class="copy-button">copy</button></pre>
1363<p>Because <code>PerformanceObserver</code> instances introduce their own additional
1364performance overhead, instances should not be left subscribed to notifications
1365indefinitely. Users should disconnect observers as soon as they are no
1366longer needed.</p>
1367<p>The <code>callback</code> is invoked when a <code>PerformanceObserver</code> is
1368notified about new <code>PerformanceEntry</code> instances. The callback receives a
1369<code>PerformanceObserverEntryList</code> instance and a reference to the
1370<code>PerformanceObserver</code>.</p>
1371<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>
1372<div class="api_metadata">
1373<span>Added in: v8.5.0</span>
1374</div>
1375<p>Disconnects the <code>PerformanceObserver</code> instance from all notifications.</p>
1376<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>
1377<div class="api_metadata">
1378<details class="changelog"><summary>History</summary>
1379<table>
1380<tbody><tr><th>Version</th><th>Changes</th></tr>
1381<tr><td>v16.7.0</td>
1382<td><p>Updated to conform to Performance Timeline Level 2. The buffered option has been added back.</p></td></tr>
1383<tr><td>v16.0.0</td>
1384<td><p>Updated to conform to User Timing Level 3. The buffered option has been removed.</p></td></tr>
1385<tr><td>v8.5.0</td>
1386<td><p><span>Added in: v8.5.0</span></p></td></tr>
1387</tbody></table>
1388</details>
1389</div>
1390<ul>
1391<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1392<ul>
1393<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> A single <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry></a> type. Must not be given
1394if <code>entryTypes</code> is already specified.</li>
1395<li><code>entryTypes</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string[]></a> An array of strings identifying the types of
1396<a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry></a> instances the observer is interested in. If not
1397provided an error will be thrown.</li>
1398<li><code>buffered</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> If true, the observer callback is called with a
1399list global <code>PerformanceEntry</code> buffered entries. If false, only
1400<code>PerformanceEntry</code>s created after the time point are sent to the
1401observer callback. <strong>Default:</strong> <code>false</code>.</li>
1402</ul>
1403</li>
1404</ul>
1405<p>Subscribes the <a href="perf_hooks.html#class-perf_hooksperformanceobserver" class="type">&#x3C;PerformanceObserver></a> instance to notifications of new
1406<a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry></a> instances identified either by <code>options.entryTypes</code>
1407or <code>options.type</code>:</p>
1408<pre><code class="language-js"><span class="hljs-keyword">const</span> {
1409  performance,
1410  <span class="hljs-title class_">PerformanceObserver</span>,
1411} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
1412
1413<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> {
1414  <span class="hljs-comment">// Called once asynchronously. `list` contains three items.</span>
1415});
1416obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'mark'</span> });
1417
1418<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> n = <span class="hljs-number">0</span>; n &#x3C; <span class="hljs-number">3</span>; n++)
1419  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>
1420</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>
1421<div class="api_metadata">
1422<span>Added in: v8.5.0</span>
1423</div>
1424<p>The <code>PerformanceObserverEntryList</code> class is used to provide access to the
1425<code>PerformanceEntry</code> instances passed to a <code>PerformanceObserver</code>.
1426The constructor of this class is not exposed to users.</p>
1427<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>
1428<div class="api_metadata">
1429<span>Added in: v8.5.0</span>
1430</div>
1431<ul>
1432<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry[]></a></li>
1433</ul>
1434<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order
1435with respect to <code>performanceEntry.startTime</code>.</p>
1436<pre><code class="language-js"><span class="hljs-keyword">const</span> {
1437  performance,
1438  <span class="hljs-title class_">PerformanceObserver</span>,
1439} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
1440
1441<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> {
1442  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(perfObserverList.<span class="hljs-title function_">getEntries</span>());
1443  <span class="hljs-comment">/**
1444   * [
1445   *   PerformanceEntry {
1446   *     name: 'test',
1447   *     entryType: 'mark',
1448   *     startTime: 81.465639,
1449   *     duration: 0
1450   *   },
1451   *   PerformanceEntry {
1452   *     name: 'meow',
1453   *     entryType: 'mark',
1454   *     startTime: 81.860064,
1455   *     duration: 0
1456   *   }
1457   * ]
1458   */</span>
1459
1460  performance.<span class="hljs-title function_">clearMarks</span>();
1461  performance.<span class="hljs-title function_">clearMeasures</span>();
1462  observer.<span class="hljs-title function_">disconnect</span>();
1463});
1464obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'mark'</span> });
1465
1466performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>);
1467performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'meow'</span>);</code> <button class="copy-button">copy</button></pre>
1468<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>
1469<div class="api_metadata">
1470<span>Added in: v8.5.0</span>
1471</div>
1472<ul>
1473<li><code>name</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1474<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1475<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry[]></a></li>
1476</ul>
1477<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order
1478with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.name</code> is
1479equal to <code>name</code>, and optionally, whose <code>performanceEntry.entryType</code> is equal to
1480<code>type</code>.</p>
1481<pre><code class="language-js"><span class="hljs-keyword">const</span> {
1482  performance,
1483  <span class="hljs-title class_">PerformanceObserver</span>,
1484} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
1485
1486<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> {
1487  <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>));
1488  <span class="hljs-comment">/**
1489   * [
1490   *   PerformanceEntry {
1491   *     name: 'meow',
1492   *     entryType: 'mark',
1493   *     startTime: 98.545991,
1494   *     duration: 0
1495   *   }
1496   * ]
1497   */</span>
1498  <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>
1499
1500  <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>));
1501  <span class="hljs-comment">/**
1502   * [
1503   *   PerformanceEntry {
1504   *     name: 'test',
1505   *     entryType: 'mark',
1506   *     startTime: 63.518931,
1507   *     duration: 0
1508   *   }
1509   * ]
1510   */</span>
1511  <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>
1512
1513  performance.<span class="hljs-title function_">clearMarks</span>();
1514  performance.<span class="hljs-title function_">clearMeasures</span>();
1515  observer.<span class="hljs-title function_">disconnect</span>();
1516});
1517obs.<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>] });
1518
1519performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>);
1520performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'meow'</span>);</code> <button class="copy-button">copy</button></pre>
1521<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>
1522<div class="api_metadata">
1523<span>Added in: v8.5.0</span>
1524</div>
1525<ul>
1526<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1527<li>Returns: <a href="perf_hooks.html#class-performanceentry" class="type">&#x3C;PerformanceEntry[]></a></li>
1528</ul>
1529<p>Returns a list of <code>PerformanceEntry</code> objects in chronological order
1530with respect to <code>performanceEntry.startTime</code> whose <code>performanceEntry.entryType</code>
1531is equal to <code>type</code>.</p>
1532<pre><code class="language-js"><span class="hljs-keyword">const</span> {
1533  performance,
1534  <span class="hljs-title class_">PerformanceObserver</span>,
1535} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
1536
1537<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> {
1538  <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>));
1539  <span class="hljs-comment">/**
1540   * [
1541   *   PerformanceEntry {
1542   *     name: 'test',
1543   *     entryType: 'mark',
1544   *     startTime: 55.897834,
1545   *     duration: 0
1546   *   },
1547   *   PerformanceEntry {
1548   *     name: 'meow',
1549   *     entryType: 'mark',
1550   *     startTime: 56.350146,
1551   *     duration: 0
1552   *   }
1553   * ]
1554   */</span>
1555  performance.<span class="hljs-title function_">clearMarks</span>();
1556  performance.<span class="hljs-title function_">clearMeasures</span>();
1557  observer.<span class="hljs-title function_">disconnect</span>();
1558});
1559obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">type</span>: <span class="hljs-string">'mark'</span> });
1560
1561performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'test'</span>);
1562performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">'meow'</span>);</code> <button class="copy-button">copy</button></pre>
1563</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>
1564<div class="api_metadata">
1565<span>Added in: v15.9.0, v14.18.0</span>
1566</div>
1567<ul>
1568<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1569<ul>
1570<li><code>lowest</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a> The lowest discernible value. Must be an integer
1571value greater than 0. <strong>Default:</strong> <code>1</code>.</li>
1572<li><code>highest</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a> The highest recordable value. Must be an integer
1573value that is equal to or greater than two times <code>lowest</code>.
1574<strong>Default:</strong> <code>Number.MAX_SAFE_INTEGER</code>.</li>
1575<li><code>figures</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The number of accuracy digits. Must be a number between
1576<code>1</code> and <code>5</code>. <strong>Default:</strong> <code>3</code>.</li>
1577</ul>
1578</li>
1579<li>Returns <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type">&#x3C;RecordableHistogram></a></li>
1580</ul>
1581<p>Returns a <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type">&#x3C;RecordableHistogram></a>.</p>
1582</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>
1583<div class="api_metadata">
1584<span>Added in: v11.10.0</span>
1585</div>
1586<ul>
1587<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
1588<ul>
1589<li><code>resolution</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The sampling rate in milliseconds. Must be greater
1590than zero. <strong>Default:</strong> <code>10</code>.</li>
1591</ul>
1592</li>
1593<li>Returns: <a href="perf_hooks.html#class-intervalhistogram-extends-histogram" class="type">&#x3C;IntervalHistogram></a></li>
1594</ul>
1595<p><em>This property is an extension by Node.js. It is not available in Web browsers.</em></p>
1596<p>Creates an <code>IntervalHistogram</code> object that samples and reports the event loop
1597delay over time. The delays will be reported in nanoseconds.</p>
1598<p>Using a timer to detect approximate event loop delay works because the
1599execution of timers is tied specifically to the lifecycle of the libuv
1600event loop. That is, a delay in the loop will cause a delay in the execution
1601of the timer, and those delays are specifically what this API is intended to
1602detect.</p>
1603<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>);
1604<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> });
1605h.<span class="hljs-title function_">enable</span>();
1606<span class="hljs-comment">// Do something.</span>
1607h.<span class="hljs-title function_">disable</span>();
1608<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">min</span>);
1609<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">max</span>);
1610<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">mean</span>);
1611<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">stddev</span>);
1612<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(h.<span class="hljs-property">percentiles</span>);
1613<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>));
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">99</span>));</code> <button class="copy-button">copy</button></pre>
1615</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>
1616<div class="api_metadata">
1617<span>Added in: v11.10.0</span>
1618</div>
1619<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>
1620<div class="api_metadata">
1621<span>Added in: v17.4.0, v16.14.0</span>
1622</div>
1623<ul>
1624<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1625</ul>
1626<p>The number of samples recorded by the histogram.</p>
1627<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>
1628<div class="api_metadata">
1629<span>Added in: v17.4.0, v16.14.0</span>
1630</div>
1631<ul>
1632<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
1633</ul>
1634<p>The number of samples recorded by the histogram.</p>
1635<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>
1636<div class="api_metadata">
1637<span>Added in: v11.10.0</span>
1638</div>
1639<ul>
1640<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1641</ul>
1642<p>The number of times the event loop delay exceeded the maximum 1 hour event
1643loop delay threshold.</p>
1644<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>
1645<div class="api_metadata">
1646<span>Added in: v17.4.0, v16.14.0</span>
1647</div>
1648<ul>
1649<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
1650</ul>
1651<p>The number of times the event loop delay exceeded the maximum 1 hour event
1652loop delay threshold.</p>
1653<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>
1654<div class="api_metadata">
1655<span>Added in: v11.10.0</span>
1656</div>
1657<ul>
1658<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1659</ul>
1660<p>The maximum recorded event loop delay.</p>
1661<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>
1662<div class="api_metadata">
1663<span>Added in: v17.4.0, v16.14.0</span>
1664</div>
1665<ul>
1666<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
1667</ul>
1668<p>The maximum recorded event loop delay.</p>
1669<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>
1670<div class="api_metadata">
1671<span>Added in: v11.10.0</span>
1672</div>
1673<ul>
1674<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1675</ul>
1676<p>The mean of the recorded event loop delays.</p>
1677<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>
1678<div class="api_metadata">
1679<span>Added in: v11.10.0</span>
1680</div>
1681<ul>
1682<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1683</ul>
1684<p>The minimum recorded event loop delay.</p>
1685<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>
1686<div class="api_metadata">
1687<span>Added in: v17.4.0, v16.14.0</span>
1688</div>
1689<ul>
1690<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
1691</ul>
1692<p>The minimum recorded event loop delay.</p>
1693<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>
1694<div class="api_metadata">
1695<span>Added in: v11.10.0</span>
1696</div>
1697<ul>
1698<li><code>percentile</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> A percentile value in the range (0, 100].</li>
1699<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1700</ul>
1701<p>Returns the value at the given percentile.</p>
1702<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>
1703<div class="api_metadata">
1704<span>Added in: v17.4.0, v16.14.0</span>
1705</div>
1706<ul>
1707<li><code>percentile</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> A percentile value in the range (0, 100].</li>
1708<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a></li>
1709</ul>
1710<p>Returns the value at the given percentile.</p>
1711<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>
1712<div class="api_metadata">
1713<span>Added in: v11.10.0</span>
1714</div>
1715<ul>
1716<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map" class="type">&#x3C;Map></a></li>
1717</ul>
1718<p>Returns a <code>Map</code> object detailing the accumulated percentile distribution.</p>
1719<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>
1720<div class="api_metadata">
1721<span>Added in: v17.4.0, v16.14.0</span>
1722</div>
1723<ul>
1724<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map" class="type">&#x3C;Map></a></li>
1725</ul>
1726<p>Returns a <code>Map</code> object detailing the accumulated percentile distribution.</p>
1727<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>
1728<div class="api_metadata">
1729<span>Added in: v11.10.0</span>
1730</div>
1731<p>Resets the collected histogram data.</p>
1732<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>
1733<div class="api_metadata">
1734<span>Added in: v11.10.0</span>
1735</div>
1736<ul>
1737<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
1738</ul>
1739<p>The standard deviation of the recorded event loop delays.</p>
1740</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>
1741<p>A <code>Histogram</code> that is periodically updated on a given interval.</p>
1742<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>
1743<div class="api_metadata">
1744<span>Added in: v11.10.0</span>
1745</div>
1746<ul>
1747<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1748</ul>
1749<p>Disables the update interval timer. Returns <code>true</code> if the timer was
1750stopped, <code>false</code> if it was already stopped.</p>
1751<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>
1752<div class="api_metadata">
1753<span>Added in: v11.10.0</span>
1754</div>
1755<ul>
1756<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
1757</ul>
1758<p>Enables the update interval timer. Returns <code>true</code> if the timer was
1759started, <code>false</code> if it was already started.</p>
1760<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>
1761<p><a href="perf_hooks.html#class-intervalhistogram-extends-histogram" class="type">&#x3C;IntervalHistogram></a> instances can be cloned via <a href="worker_threads.html#class-messageport" class="type">&#x3C;MessagePort></a>. On the receiving
1762end, the histogram is cloned as a plain <a href="perf_hooks.html#class-histogram" class="type">&#x3C;Histogram></a> object that does not
1763implement the <code>enable()</code> and <code>disable()</code> methods.</p>
1764</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>
1765<div class="api_metadata">
1766<span>Added in: v15.9.0, v14.18.0</span>
1767</div>
1768<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>
1769<div class="api_metadata">
1770<span>Added in: v17.4.0, v16.14.0</span>
1771</div>
1772<ul>
1773<li><code>other</code> <a href="perf_hooks.html#class-recordablehistogram-extends-histogram" class="type">&#x3C;RecordableHistogram></a></li>
1774</ul>
1775<p>Adds the values from <code>other</code> to this histogram.</p>
1776<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>
1777<div class="api_metadata">
1778<span>Added in: v15.9.0, v14.18.0</span>
1779</div>
1780<ul>
1781<li><code>val</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt" class="type">&#x3C;bigint></a> The amount to record in the histogram.</li>
1782</ul>
1783<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>
1784<div class="api_metadata">
1785<span>Added in: v15.9.0, v14.18.0</span>
1786</div>
1787<p>Calculates the amount of time (in nanoseconds) that has passed since the
1788previous call to <code>recordDelta()</code> and records that amount in the histogram.</p>
1789</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>
1790<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>
1791<p>The following example uses the <a href="async_hooks.html">Async Hooks</a> and Performance APIs to measure
1792the actual duration of a Timeout operation (including the amount of time it took
1793to execute the callback).</p>
1794<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>;
1795<span class="hljs-keyword">const</span> async_hooks = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:async_hooks'</span>);
1796<span class="hljs-keyword">const</span> {
1797  performance,
1798  <span class="hljs-title class_">PerformanceObserver</span>,
1799} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
1800
1801<span class="hljs-keyword">const</span> set = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Set</span>();
1802<span class="hljs-keyword">const</span> hook = async_hooks.<span class="hljs-title function_">createHook</span>({
1803  <span class="hljs-title function_">init</span>(<span class="hljs-params">id, type</span>) {
1804    <span class="hljs-keyword">if</span> (type === <span class="hljs-string">'Timeout'</span>) {
1805      performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Init`</span>);
1806      set.<span class="hljs-title function_">add</span>(id);
1807    }
1808  },
1809  <span class="hljs-title function_">destroy</span>(<span class="hljs-params">id</span>) {
1810    <span class="hljs-keyword">if</span> (set.<span class="hljs-title function_">has</span>(id)) {
1811      set.<span class="hljs-title function_">delete</span>(id);
1812      performance.<span class="hljs-title function_">mark</span>(<span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Destroy`</span>);
1813      performance.<span class="hljs-title function_">measure</span>(<span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>`</span>,
1814                          <span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Init`</span>,
1815                          <span class="hljs-string">`Timeout-<span class="hljs-subst">${id}</span>-Destroy`</span>);
1816    }
1817  },
1818});
1819hook.<span class="hljs-title function_">enable</span>();
1820
1821<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> {
1822  <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>]);
1823  performance.<span class="hljs-title function_">clearMarks</span>();
1824  performance.<span class="hljs-title function_">clearMeasures</span>();
1825  observer.<span class="hljs-title function_">disconnect</span>();
1826});
1827obs.<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> });
1828
1829<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>
1830<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>
1831<p>The following example measures the duration of <code>require()</code> operations to load
1832dependencies:</p>
1833<!-- eslint-disable no-global-assign -->
1834<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>;
1835<span class="hljs-keyword">const</span> {
1836  performance,
1837  <span class="hljs-title class_">PerformanceObserver</span>,
1838} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
1839<span class="hljs-keyword">const</span> mod = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:module'</span>);
1840
1841<span class="hljs-comment">// Monkey patch the require function</span>
1842mod.<span class="hljs-property">Module</span>.<span class="hljs-property"><span class="hljs-keyword">prototype</span></span>.<span class="hljs-property">require</span> =
1843  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>);
1844<span class="hljs-built_in">require</span> = performance.<span class="hljs-title function_">timerify</span>(<span class="hljs-built_in">require</span>);
1845
1846<span class="hljs-comment">// Activate the observer</span>
1847<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> {
1848  <span class="hljs-keyword">const</span> entries = list.<span class="hljs-title function_">getEntries</span>();
1849  entries.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">entry</span>) =></span> {
1850    <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>);
1851  });
1852  performance.<span class="hljs-title function_">clearMarks</span>();
1853  performance.<span class="hljs-title function_">clearMeasures</span>();
1854  obs.<span class="hljs-title function_">disconnect</span>();
1855});
1856obs.<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> });
1857
1858<span class="hljs-built_in">require</span>(<span class="hljs-string">'some-module'</span>);</code> <button class="copy-button">copy</button></pre>
1859<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>
1860<p>The following example is used to trace the time spent by HTTP client
1861(<code>OutgoingMessage</code>) and HTTP request (<code>IncomingMessage</code>). For HTTP client,
1862it means the time interval between starting the request and receiving the
1863response, and for HTTP request, it means the time interval between receiving
1864the request and sending the response:</p>
1865<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>;
1866<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>);
1867<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:http'</span>);
1868
1869<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> {
1870  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> {
1871    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(item);
1872  });
1873});
1874
1875obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'http'</span>] });
1876
1877<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">PORT</span> = <span class="hljs-number">8080</span>;
1878
1879http.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">req, res</span>) =></span> {
1880  res.<span class="hljs-title function_">end</span>(<span class="hljs-string">'ok'</span>);
1881}).<span class="hljs-title function_">listen</span>(<span class="hljs-variable constant_">PORT</span>, <span class="hljs-function">() =></span> {
1882  http.<span class="hljs-title function_">get</span>(<span class="hljs-string">`http://127.0.0.1:<span class="hljs-subst">${PORT}</span>`</span>);
1883});</code> <button class="copy-button">copy</button></pre>
1884<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>
1885<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>;
1886<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>);
1887<span class="hljs-keyword">const</span> net = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:net'</span>);
1888<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> {
1889  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> {
1890    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(item);
1891  });
1892});
1893obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'net'</span>] });
1894<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">PORT</span> = <span class="hljs-number">8080</span>;
1895net.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">socket</span>) =></span> {
1896  socket.<span class="hljs-title function_">destroy</span>();
1897}).<span class="hljs-title function_">listen</span>(<span class="hljs-variable constant_">PORT</span>, <span class="hljs-function">() =></span> {
1898  net.<span class="hljs-title function_">connect</span>(<span class="hljs-variable constant_">PORT</span>);
1899});</code> <button class="copy-button">copy</button></pre>
1900<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>
1901<pre><code class="language-js"><span class="hljs-meta">'use strict'</span>;
1902<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>);
1903<span class="hljs-keyword">const</span> dns = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:dns'</span>);
1904<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> {
1905  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> {
1906    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(item);
1907  });
1908});
1909obs.<span class="hljs-title function_">observe</span>({ <span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'dns'</span>] });
1910dns.<span class="hljs-title function_">lookup</span>(<span class="hljs-string">'localhost'</span>, <span class="hljs-function">() =></span> {});
1911dns.<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>
1912        <!-- API END -->
1913      </div>
1914    </div>
1915  </div>
1916</body>
1917</html>
1918