Performance
performance.measure()
Records a duration between marks or explicitly supplied times. Its duration is expressed in milliseconds. Use unique names for concurrent work or avoid shared mark names; clear entries after use. Tested on Node.js 22.16.0. Example output (one line per entry): ["4 measure"]. The marks in this example are synthetic timestamps for deterministic arithmetic, not measured execution times.
Formal Syntax & Structure
nodejs syntaxnodejs
performance.measure(name[, startMarkOrOptions[, endMark]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Measure name. |
| startMarkOrOptions | string | object | Start mark or measurement options. |
| endMark | string | End mark. |
Return Value
PerformanceMeasure
Recorded duration.
Working Example
Example Snippetnodejs
import { performance } from 'node:perf_hooks';try { performance.mark('a', { startTime: 10 }); performance.mark('b', { startTime: 14 }); const m = performance.measure('span', 'a', 'b'); console.log(m.duration, m.entryType);}finally { performance.clearMarks('a'); performance.clearMarks('b'); performance.clearMeasures('span');}