Rule of thumb · DIYNº 137 / 167

A naive timer drifts, a correct one can’t

Adding up tick intervals compounds every small delay into permanent error — computing elapsed time as now minus a fixed start point means a single slow tick costs you nothing, because the next measurement is still anchored to the same origin.

Why it works

Verified against a realistic scenario: a timer ticking every 100ms, each tick actually taking 103ms under normal browser load, reports a perfect 60.00s after 600 ticks while only 58.20s has really passed — a 1.8-second error in under a minute from accumulation alone.

When it fails

Computing from a fixed start point removes accumulated drift, not every error: a suspended laptop, a throttled background tab, or a system clock adjusted by NTP can all move the answer. The right clock for elapsed time is a monotonic one, not the wall clock.

Do it exactly

Estimate with the rule, then check it against the calculator that models it properly.

Open Precision Timer & Stopwatch →

More in DIY

← PreviousEgg cooking time scales with mass to the two-thirds power, not linearly Next →Mid-market is not what you get at the bank

Why do JavaScript timers drift?

Adding up tick intervals compounds every small delay into permanent error — computing elapsed time as now minus a fixed start point means a single slow tick costs you nothing, because the next measurement is still anchored to the same origin. Verified against a realistic scenario: a timer ticking every 100ms, each tick actually taking 103ms under normal browser load, reports a perfect 60.00s after 600 ticks while only 58.20s has really passed — a 1.8-second error in under a minute from accumulation alone.

Browse all 167 rules of thumb →