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

NameTypeDescription
namestringMeasure name.
startMarkOrOptionsstring | objectStart mark or measurement options.
endMarkstringEnd 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');}
Node.js Reference