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
@@ -95,6 +103,8 @@ added: v8.5.0
95
103
96
104
* {PerformanceNodeTiming}
97
105
106
+ _ This property is an extension by Node.js. It is not available in Web browsers._
107
+
98
108
An instance of the ` PerformanceNodeTiming ` class that provides performance
99
109
metrics for specific Node.js operational milestones.
100
110
@@ -125,6 +135,8 @@ added: v8.5.0
125
135
126
136
* ` fn ` {Function}
127
137
138
+ _ This property is an extension by Node.js. It is not available in Web browsers._
139
+
128
140
Wraps a function within a new function that measures the running time of the
129
141
wrapped function. A ` PerformanceObserver ` must be subscribed to the ` 'function' `
130
142
event type in order for the timing details to be accessed.
@@ -192,8 +204,15 @@ added: v8.5.0
192
204
193
205
* {string}
194
206
195
- The type of the performance entry. Currently it may be one of: ` 'node' ` ,
196
- ` 'mark' ` , ` 'measure' ` , ` 'gc' ` , ` 'function' ` , ` 'http2' ` or ` 'http' ` .
207
+ The type of the performance entry. It may be one of:
208
+
209
+ * ` 'node' ` (Node.js only)
210
+ * ` 'mark' ` (available on the Web)
211
+ * ` 'measure' ` (available on the Web)
212
+ * ` 'gc' ` (Node.js only)
213
+ * ` 'function' ` (Node.js only)
214
+ * ` 'http2' ` (Node.js only)
215
+ * ` 'http' ` (Node.js only)
197
216
198
217
### ` performanceEntry.kind `
199
218
<!-- YAML
@@ -202,6 +221,8 @@ added: v8.5.0
202
221
203
222
* {number}
204
223
224
+ _ This property is an extension by Node.js. It is not available in Web browsers._
225
+
205
226
When ` performanceEntry.entryType ` is equal to ` 'gc' ` , the ` performance.kind `
206
227
property identifies the type of garbage collection operation that occurred.
207
228
The value may be one of:
@@ -218,6 +239,8 @@ added: v13.9.0
218
239
219
240
* {number}
220
241
242
+ _ This property is an extension by Node.js. It is not available in Web browsers._
243
+
221
244
When ` performanceEntry.entryType ` is equal to ` 'gc' ` , the ` performance.flags `
222
245
property contains additional information about garbage collection operation.
223
246
The value may be one of:
@@ -235,7 +258,10 @@ The value may be one of:
235
258
added: v8.5.0
236
259
-->
237
260
238
- Provides timing details for Node.js itself.
261
+ _ This property is an extension by Node.js. It is not available in Web browsers._
262
+
263
+ Provides timing details for Node.js itself. The constructor of this class
264
+ is not exposed to users.
239
265
240
266
### ` performanceNodeTiming.bootstrapComplete `
241
267
<!-- YAML
@@ -300,7 +326,7 @@ added: v8.5.0
300
326
The high resolution millisecond timestamp at which the V8 platform was
301
327
initialized.
302
328
303
- ## Class: ` PerformanceObserver `
329
+ ## Class: ` perf_hooks. PerformanceObserver`
304
330
305
331
### ` new PerformanceObserver(callback) `
306
332
<!-- YAML
@@ -402,6 +428,7 @@ added: v8.5.0
402
428
403
429
The ` PerformanceObserverEntryList ` class is used to provide access to the
404
430
` PerformanceEntry ` instances passed to a ` PerformanceObserver ` .
431
+ The constructor of this class is not exposed to users.
405
432
406
433
### ` performanceObserverEntryList.getEntries() `
407
434
<!-- YAML
@@ -449,6 +476,8 @@ added: v11.10.0
449
476
than zero. ** Default:** ` 10 ` .
450
477
* Returns: {Histogram}
451
478
479
+ _ This property is an extension by Node.js. It is not available in Web browsers._
480
+
452
481
Creates a ` Histogram ` object that samples and reports the event loop delay
453
482
over time. The delays will be reported in nanoseconds.
454
483
@@ -477,7 +506,10 @@ console.log(h.percentile(99));
477
506
<!-- YAML
478
507
added: v11.10.0
479
508
-->
480
- Tracks the event loop delay at a given sampling rate.
509
+ Tracks the event loop delay at a given sampling rate. The constructor of
510
+ this class not exposed to users.
511
+
512
+ _ This property is an extension by Node.js. It is not available in Web browsers._
481
513
482
514
#### ` histogram.disable() `
483
515
<!-- YAML
@@ -651,5 +683,9 @@ require('some-module');
651
683
652
684
[ `'exit'` ] : process.html#process_event_exit
653
685
[ `timeOrigin` ] : https://w3c.github.io/hr-time/#dom-performance-timeorigin
686
+ [ `window.performance` ] : https://developer.mozilla.org/en-US/docs/Web/API/Window/performance
654
687
[ Async Hooks ] : async_hooks.html
655
- [ W3C Performance Timeline ] : https://w3c.github.io/performance-timeline/
688
+ [ High Resolution Time ] : https://www.w3.org/TR/hr-time-2
689
+ [ Performance Timeline ] : https://w3c.github.io/performance-timeline/
690
+ [ Web Performance APIs ] : https://w3c.github.io/perf-timing-primer/
691
+ [ User Timing ] : https://www.w3.org/TR/user-timing/
0 commit comments