Skip to content
UniKit

Scriptable stopwatch

A stopwatch state machine: start, pause, lap and reset are pure state transitions, and elapsed milliseconds and laps are computed from a caller-supplied now value, so time can be injected and the result reproduces exactly. The page only runs the timer and renders.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Stopwatch

00:00:00.000Elapsed · Not started
LapsLaps taken: 0

No laps yet — press "Lap" to record the first one

Script mode (reproducible)

One command per line: start, pause, resume, lap, reset. A number advances time by that many milliseconds (1500 or +1500) and accepts units (2s, 1m, 3step). Lines starting with # are comments.

Stopwatch script (one command per line)

Used when a script writes 3step; must be between 1 and 60000.

Script result

Time comes from the script, not the system clock, so the same script always produces the same timeline. The stopwatch buttons above drive the same state machine.

Write commands in the script box (for example start, +1500, lap) to see the timeline

Commands: 0Laps: 0Final time: 00:00:00.000

What this tool does

  • Use it as an ordinary stopwatch: start, pause, lap and reset, with both split and cumulative times per lap.
  • Write a race, training or interview flow as a script to get a line-by-line timeline and check when each stage should end.
  • Test timing code: the state machine takes time from the script, so the same script always yields the same result and can be asserted directly in unit tests.

Example

Input

start
+1500
lap
pause

Output

Final: 00:00:01.500
Laps: 1
1. start 00:00:00.000
2. +1500ms 00:00:01.500
3. lap #1 00:00:01.500
4. pause 00:00:01.500

One command per line and time is advanced by the script (+1500 moves the clock 1500 ms), so the output does not depend on the system clock and always reproduces.

Frequently asked questions

Which commands and time formats are supported?

Commands: start (also resumes), pause, resume, lap, reset. Time is a number of milliseconds to advance and accepts +1500, 2s, 1m and 3step; without a unit it means milliseconds, and step is multiplied by stepMs. Time can never move below zero. Blank lines and lines starting with # are ignored.

Do the buttons and script mode use different logic?

No. Both drive the same pure state machine (start / pause / lap / reset plus elapsed). Only the time source differs: the buttons read the real clock and refresh every 50 ms, while script mode uses the time advanced inside the script, which is why only script mode is exactly reproducible.

How is a lap computed?

lap stores the cumulative elapsed time, so the split is this cumulative value minus the previous one. Taking a lap before starting gives 0, and laps taken while paused do not add time.

What precision does it offer?

The state machine works in whole milliseconds and always formats HH:MM:SS.mmm with no cap on hours. On the page the display is limited by the browser timer (about 50 ms plus background throttling), so it is meant for human reading rather than high-precision timing — use script mode when you need exact numbers.

Keywords:stopwatch onlinelap timer

Related tools