Skip to content
Sarj Code Standards

prefer-monotonic-for-elapsed-time

Measure elapsed time with a monotonic clock rather than wall-clock timestamps.

Why

Clock corrections can make Date.now differences jump or turn negative even when a duration is the only intended observation.

Fix

Use performance.now consistently at both ends of a duration. Keep wall-clock timestamps when they are stored, displayed or otherwise part of the contract.

Examples

Before — flagged Detect the demonstrated gap
app.ts
const start = Date.now();
consume(Date.now() - start);
After — preferred Preserve the declared boundary
app.ts
const start = performance.now();
consume(performance.now() - start);