Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

performance.now() — measuring elapsed time

performance.now() returns a timestamp in milliseconds relative to the environment's time origin. Subtracting two readings measures elapsed time without being affected by system-clock adjustments.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

const start = performance.now();
// Run the operation being measured.
const elapsedMs = performance.now() - start;

performance.now() takes no arguments and returns a DOMHighResTimeStamp: a number in milliseconds that can include a fractional part. The value is relative to the environment's time origin, not the Unix epoch. performance.timeOrigin describes that origin.

To measure elapsed time, subtract the earlier reading from the later reading in the same environment. The clock is monotonic: readings do not decrease because of system-clock adjustments. In contrast, Date.now() represents calendar time and can be affected by those adjustments. Do not directly subtract readings from contexts with different time origins.

Browsers may reduce resolution for security reasons; consecutive readings can be equal. A fractional part does not guarantee a particular accuracy. The example checks the computation result and a nonnegative duration instead of a specific number of milliseconds.

This is a Web API defined by High Resolution Time, not a core ECMAScript function. The specification exposes it in Window and Worker; check availability in the target browser, not from the repository's Node version. Reading the clock alone does not record a performance timeline entry; User Timing provides named measurements through performance.mark() and performance.measure().

Examples

const start = performance.now();
let sum = 0;
for (let i = 1; i <= 1000; i++) {
  sum += i;
}
const elapsedMs = performance.now() - start;
console.log(sum);
console.log(Number.isFinite(elapsedMs) && elapsedMs >= 0);

Result

500500
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources