The stopwatch supports lap timing; the countdown rings and reminds you when time is up. Handy for workouts, eggs and pomodoro focus.
A naive timer counts with setInterval and adds one tick per callback. That drifts, because the callback is queued and never fires at exactly the requested interval — under load the error accumulates, and after ten minutes a stopwatch built this way can be visibly wrong.
The reliable approach is to record the timestamp at which timing started, then on every animation frame compute now minus start and display that. Because each reading is derived from the clock rather than accumulated from previous readings, error cannot build up.
| Source | Behaviour |
|---|---|
Date.now() | Wall-clock time. Can jump forwards or backwards if the system time is adjusted or a network sync occurs. |
performance.now() | Monotonic and high-resolution. Cannot go backwards, and is not affected by clock changes — the correct choice for durations. |
Browsers throttle timers and animation frames in inactive tabs to save power, sometimes to once per second or less. A counter that increments per frame will therefore under-count while the tab is hidden. Timestamp-based timing is immune to this, since the clock keeps running even when the display does not update — which is a further reason to prefer it.
Browser timers are deliberately coarsened for security, so sub-millisecond precision is not attainable. For ordinary work — cooking, workouts, presentations — this is irrelevant. For benchmarking code, run many iterations and compare distributions rather than trusting a single reading.
Displaying hundredths of a second invites more trust than manual timing can support. Reaction to a visual cue averages around 200–250 ms; to a sound it is closer to 150–180 ms. Both the start and the stop press carry that delay, so a hand-timed interval carries several tenths of a second of uncertainty before any measurement is taken.
Worse, the error is systematic rather than random: people press consistently late, so repeating the measurement tightens the spread but does not remove the offset. Anything that must be compared against a standard — a race, a reaction test, an experiment — needs a photogate, an audio trigger or a software timestamp, not a human thumb.
A readout of 12.34 s means the display resolves hundredths, not that the interval was 12.34 seconds. That distinction decides which number is worth quoting:
| Task | Useful resolution | Why |
|---|---|---|
| Cooking, steeping, baking | Seconds | Ingredients and heat transfer vary far more than a second |
| Workout intervals | 0.1 s | Effort varies by more than the timer does |
| Presentation timing | Seconds | Rehearsal pace is never repeatable to the tenth |
| Reaction tests | Milliseconds | Only meaningful if input and display latency are known |
| Code benchmarking | Microseconds, repeated | A single run is dominated by noise and JIT warm-up |
Quoting more digits than the method supports is the most common error in timed work — a result written as 12.34 seconds when the realistic uncertainty is half a second misleads anyone who later compares it.