Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Node.js · Const

performance

Node.js’s performance object provides high-resolution timing and Performance Timeline operations for measuring code and inspecting runtime metrics.

How it works

The performance object from node:perf_hooks exposes high-resolution timing and the Performance Timeline for the current Node.js process. Record marks, create measures between them, inspect entries, and clear entries when they are no longer needed.

Syntax

import { performance } from 'node:perf_hooks';

Parameters

NameTypeDescription
namestringName of the mark or measure entry; measure calls may also accept start and end mark names.
startMarkstringOptional starting mark name or timing point for a measure.
endMarkstringOptional ending mark name or timing point for a measure.

Returns

A Performance object that provides timing methods and access to entries in the Performance Timeline.

Key points

  • performance is the central object for collecting timing information from the running Node.js process.
  • Its programming model resembles the browser Performance API, making familiar marks, measures, and timeline queries available in Node.js.
  • performance.now() gives a high-resolution elapsed-time value in milliseconds relative to process start.
  • Use performance.mark() to record named points that can later define measurement boundaries.
  • Use performance.measure() to create a duration entry between marks or other supported timing points.
  • Timeline entries can be retrieved through the performance entry-query methods, including filtering by name or type.

Common mistakes

  • Performance entries remain available until explicitly cleared; remove them after collecting results when long-running processes could accumulate measurements.

Example: Measure an asynchronous operation

import { performance } from 'node:perf_hooks';

performance.mark('start');
await new Promise((resolve) => setTimeout(resolve, 20));
performance.mark('end');
performance.measure('work', 'start', 'end');

const [entry] = performance.getEntriesByName('work');
console.log(`${entry.name}: ${entry.duration.toFixed(2)} ms`);

Creates marks around asynchronous work, measures the interval, and prints the resulting duration.

When to use it

Benchmark an operation

Measure the duration of synchronous or asynchronous application work.

Trace lifecycle phases

Mark phases such as initialization, request handling, and shutdown.

Instrument runtime behavior

Collect and inspect timing entries for diagnostics or instrumentation.

  • PerformanceEntry
  • PerformanceMark
  • PerformanceMeasure
  • PerformanceObserver
  • performance.mark()
  • performance.measure()
  • performance.now()
  • performance.getEntriesByName()

Source: Performance measurement APIs | Node.js v26.10.0 Documentation. Checked 2026-10-15.