Stopwatch
Press Start, and take lap times while the clock runs.
0:00.00
Space starts and stops, L takes a lap, R resets.
How it works
The stopwatch measures with the browser’s clock for timing, performance.now(), rather than counting screen updates. That clock is not affected if the computer’s clock is changed, but except on Windows it stands still while the computer sleeps, so the time asleep is added from the computer’s ordinary clock. The time stays right even if the tab sits in the background for a while.
The lap time is the time since the previous lap; the total is the time since the start. With two laps or more, the fastest and slowest are marked.
On the keyboard, Space starts and stops, L takes a lap and R resets when the clock is stopped.
The hundredths show what the clock measured, but a human press has a reaction time of around two tenths of a second. That is why races are timed with photocells.
How the tool measures
The stopwatch reads two clocks: the browser’s clock for measurements, performance.now(), and the computer’s ordinary clock, Date.now(). At each reading, the time since the previous reading is added to what has already been measured, including earlier runs. It reads them once per screen frame, once a second or as often as the browser allows while the tab is in the background, and straight away when the tab is shown again. Hundredths are rounded down: 65.437 seconds shows as 1:05.43. Past an hour the hours come first, as in 1:02:03.45.
A lap stores the total time at the moment you press, and the lap time is the difference from the previous lap. Each time is rounded down on its own, so the lap times shown can add up to a hundredth less than the total. With laps of 62.415 and 62.625 seconds the lap times show as 1:02.41 and 1:02.62, which add up to 2:05.03, while the total shows 2:05.04. Fastest and slowest are decided on the hundredths shown. If all laps show the same time, none is marked, and if several laps share the fastest or slowest time, they are all marked.
The clock that measures
The W3C High Resolution Time specification describes performance.now() as a monotonic clock: it never goes backwards and cannot be changed by adjustments to the system clock, and a browser slowing down timers in a background tab should not let that affect its accuracy. But according to MDN it only keeps running while the computer sleeps in browsers on Windows. In Chrome, Firefox and Safari on other systems it stands still during sleep, and the bug is reported to all three. The computer’s ordinary clock, Date.now(), counts the sleep but can be changed, for instance when it synchronises with a time server.
So the stopwatch counts each step between two readings with performance.now(), except when the computer’s clock has moved more than two seconds further. Then the measuring clock stood still while the computer slept, and the step is taken from the computer’s clock. A clock set back therefore never affects the time, and a night in sleep mode is counted on every system. A clock set forward by more than two seconds while the stopwatch runs is counted as time passed, though, because from inside the web page it cannot be told apart from sleep.
Compared with race timing
World Athletics rules round the other way. With hand timing on the track, a time that is not an exact tenth is rounded up to the next longer tenth, so 10.11 seconds becomes 10.2. With photo finish, times in races up to and including 10,000 metres are rounded up to the next hundredth. A time of 65.437 seconds, which this stopwatch shows as 1:05.43, would therefore be recorded as 1:05.44 with photo finish and 1:05.5 by hand. Hand timing uses three timekeepers, and if all three disagree, the middle time is official.