A latency number is meaningful only when its start and end points are defined. Client-perceived time may include DNS, TLS, network transit, queueing, server work, and response transfer. Server handler time measures a narrower slice. Reporting one as the other leads to the wrong optimization.
Choose a measurement boundary
For user experience, measure from the client action to the complete response needed by the interface. For service diagnostics, record request arrival, queue wait, handler duration, and dependency calls. Use monotonic clocks for elapsed time and correlate spans with a request ID. Avoid subtracting wall-clock timestamps from machines whose clocks may differ.
Report sample size and percentiles such as p50, p95, and p99. Tail latency often determines whether users encounter a stall, while an average can conceal it. Separate successful requests from timeouts and errors; a fast failure should not make the service look faster. Segment by route and a small set of meaningful dimensions without exposing personal data.
Keep the benchmark representative
Use realistic payloads, concurrency, warm-up, and geographic placement. Do not benchmark from the same host if that bypasses the network path users depend on. Record the client version, server revision, and test conditions. Compare like with like and repeat tests to understand variance.
A latency goal should reflect the user task and downstream dependencies. Track it over time and connect regressions to deployments. Measurement is useful when it tells you which part of the path needs attention.
A small measurement with a known boundary
A Node.js 24.16.0 process served a tiny JSON health response on the loopback interface. The same process made requests sequentially, discarded five warm-up requests, and recorded 50 completed responses. All 50 returned HTTP 200. Including reading the entire response body, the nearest-rank median was 0.75 ms and the 95th percentile was 1.91 ms. These numbers describe that one local run, with no network between hosts, database query, or concurrent client load. Node.js timing APIs
In an application benchmark, publish the client-observed interval, warm-up count, success and failure rates, response size and concurrency. A server trace can explain which part of a slow request occurred in the app. Use performance.now for the elapsed interval in the example. Other clients may measure time to the first byte, which answers a different question from time to the fully downloaded result.
Worked example
Save this as measure.mjs and run it with Node.js 24. It listens only on loopback and reports the two nearest-rank percentiles for the measured sample.
jsimport { createServer } from "node:http"; import { performance } from "node:perf_hooks"; const server = createServer((_request, response) => { response.setHeader("Content-Type", "application/json"); response.end('{"status":"ok"}'); }); await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); const url = "http://127.0.0.1:" + server.address().port + "/health"; async function measure() { const start = performance.now(); const response = await fetch(url); await response.text(); if (response.status !== 200) throw new Error("Unexpected health status"); return performance.now() - start; } try { for (let index = 0; index < 5; index++) await measure(); const times = []; for (let index = 0; index < 50; index++) times.push(await measure()); times.sort((a, b) => a - b); console.log({ samples: times.length, p50Ms: times[24], p95Ms: times[47] }); } finally { await new Promise((resolve) => server.close(resolve)); }




Community
Discussion
Loading comments…