1
- # Performance Timing API
1
+ # Performance Measurement APIs
2
2
3
3
<!-- introduced_in=v8.5.0-->
4
4
5
5
> Stability: 2 - Stable
6
6
7
- The Performance Timing API provides an implementation of the
8
- [ W3C Performance Timeline] [ ] specification. The purpose of the API
9
- is to support collection of high resolution performance metrics.
10
- This is the same Performance API as implemented in modern Web browsers.
7
+ This module provides an implementation of a subset of the W3C
8
+ [ Web Performance APIs] [ ] as well as additional APIs for
9
+ Node.js-specific performance measurements.
10
+
11
+ Node.js supports the following [ Web Performance APIs] [ ] :
12
+
13
+ * [ High Resolution Time] [ ]
14
+ * [ Performance Timeline] [ ]
15
+ * [ User Timing] [ ]
11
16
12
17
``` js
13
18
const { PerformanceObserver , performance } = require (' perf_hooks' );
@@ -28,11 +33,14 @@ doSomeLongRunningProcess(() => {
28
33
});
29
34
```
30
35
31
- ## Class: ` Performance `
36
+ ## ` perf_hooks.performance `
32
37
<!-- YAML
33
38
added: v8.5.0
34
39
-->
35
40
41
+ An object that can be used to collect performance metrics from the current
42
+ Node.js instance. It is similar to [ ` window.performance ` ] [ ] in browsers.
43
+
36
44
### ` performance.clearMarks([name]) `
37
45
<!-- YAML
38
46
added: v8.5.0
@@ -93,6 +101,8 @@ added: v8.5.0
93
101
94
102
* {PerformanceNodeTiming}
95
103
104
+ _ This property is an extension by Node.js. It is not available in Web browsers._
105
+
96
106
An instance of the ` PerformanceNodeTiming ` class that provides performance
97
107
metrics for specific Node.js operational milestones.
98
108
@@ -123,6 +133,8 @@ added: v8.5.0
123
133
124
134
* ` fn ` {Function}
125
135
136
+ _ This property is an extension by Node.js. It is not available in Web browsers._
137
+
126
138
Wraps a function within a new function that measures the running time of the
127
139
wrapped function. A ` PerformanceObserver ` must be subscribed to the ` 'function' `
128
140
event type in order for the timing details to be accessed.
@@ -190,8 +202,15 @@ added: v8.5.0
190
202
191
203
* {string}
192
204
193
- The type of the performance entry. Currently it may be one of: ` 'node' ` ,
194
- ` 'mark' ` , ` 'measure' ` , ` 'gc' ` , ` 'function' ` , ` 'http2' ` or ` 'http' ` .
205
+ The type of the performance entry. It may be one of:
206
+
207
+ * ` 'node' ` (Node.js only)
208
+ * ` 'mark' ` (available on the Web)
209
+ * ` 'measure' ` (available on the Web)
210
+ * ` 'gc' ` (Node.js only)
211
+ * ` 'function' ` (Node.js only)
212
+ * ` 'http2' ` (Node.js only)
213
+ * ` 'http' ` (Node.js only)
195
214
196
215
### ` performanceEntry.kind `
197
216
<!-- YAML
@@ -200,6 +219,8 @@ added: v8.5.0
200
219
201
220
* {number}
202
221
222
+ _ This property is an extension by Node.js. It is not available in Web browsers._
223
+
203
224
When ` performanceEntry.entryType ` is equal to ` 'gc' ` , the ` performance.kind `
204
225
property identifies the type of garbage collection operation that occurred.
205
226
The value may be one of:
@@ -216,6 +237,8 @@ added: v13.9.0
216
237
217
238
* {number}
218
239
240
+ _ This property is an extension by Node.js. It is not available in Web browsers._
241
+
219
242
When ` performanceEntry.entryType ` is equal to ` 'gc' ` , the ` performance.flags `
220
243
property contains additional information about garbage collection operation.
221
244
The value may be one of:
@@ -233,7 +256,10 @@ The value may be one of:
233
256
added: v8.5.0
234
257
-->
235
258
236
- Provides timing details for Node.js itself.
259
+ _ This property is an extension by Node.js. It is not available in Web browsers._
260
+
261
+ Provides timing details for Node.js itself. The constructor of this class
262
+ is not exposed to users.
237
263
238
264
### ` performanceNodeTiming.bootstrapComplete `
239
265
<!-- YAML
@@ -298,7 +324,7 @@ added: v8.5.0
298
324
The high resolution millisecond timestamp at which the V8 platform was
299
325
initialized.
300
326
301
- ## Class: ` PerformanceObserver `
327
+ ## Class: ` perf_hooks. PerformanceObserver`
302
328
303
329
### ` new PerformanceObserver(callback) `
304
330
<!-- YAML
@@ -400,6 +426,7 @@ added: v8.5.0
400
426
401
427
The ` PerformanceObserverEntryList ` class is used to provide access to the
402
428
` PerformanceEntry ` instances passed to a ` PerformanceObserver ` .
429
+ The constructor of this class is not exposed to users.
403
430
404
431
### ` performanceObserverEntryList.getEntries() `
405
432
<!-- YAML
@@ -447,6 +474,8 @@ added: v11.10.0
447
474
than zero. ** Default:** ` 10 ` .
448
475
* Returns: {Histogram}
449
476
477
+ _ This property is an extension by Node.js. It is not available in Web browsers._
478
+
450
479
Creates a ` Histogram ` object that samples and reports the event loop delay
451
480
over time. The delays will be reported in nanoseconds.
452
481
@@ -475,7 +504,10 @@ console.log(h.percentile(99));
475
504
<!-- YAML
476
505
added: v11.10.0
477
506
-->
478
- Tracks the event loop delay at a given sampling rate.
507
+ Tracks the event loop delay at a given sampling rate. The constructor of
508
+ this class not exposed to users.
509
+
510
+ _ This property is an extension by Node.js. It is not available in Web browsers._
479
511
480
512
#### ` histogram.disable() `
481
513
<!-- YAML
@@ -649,5 +681,9 @@ require('some-module');
649
681
650
682
[ `'exit'` ] : process.html#process_event_exit
651
683
[ `timeOrigin` ] : https://w3c.github.io/hr-time/#dom-performance-timeorigin
684
+ [ `window.performance` ] : https://developer.mozilla.org/en-US/docs/Web/API/Window/performance
652
685
[ Async Hooks ] : async_hooks.html
653
- [ W3C Performance Timeline ] : https://w3c.github.io/performance-timeline/
686
+ [ High Resolution Time ] : https://www.w3.org/TR/hr-time-2
687
+ [ Performance Timeline ] : https://w3c.github.io/performance-timeline/
688
+ [ Web Performance APIs ] : https://w3c.github.io/perf-timing-primer/
689
+ [ User Timing ] : https://www.w3.org/TR/user-timing/
0 commit comments