Node.js Reference ยท Globals and Console
Node.js console.time() method
Reference for console.time(), console.timeLog() and console.timeEnd() in Node.js: measuring elapsed time with labels, formats, warnings and better alternatives.
console.time(label) starts a named timer. console.timeLog(label) prints the elapsed time without stopping it, and console.timeEnd(label) prints it and removes the timer. The label ties the calls together; without one it is default.
The output looks like label: 1.234ms, switching to seconds, minutes or hours for longer durations. The numbers differ on every run, so tests and documentation rarely show them.
console.time('load'); // ... work ... console.timeEnd('load'); // load: 12.345ms
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.
Syntax
console.time([label = 'default']): void console.timeLog([label = 'default'][, ...data]): void console.timeEnd([label = 'default']): void
| Name | Description |
|---|---|
label |
Name of the timer. Case-sensitive. Default 'default'. |
...data |
Extra values printed after the elapsed time by timeLog(). |
Returns: undefined.
Edge cases: starting a label that already exists emits a warning (Label 'x' already exists for console.time()) and keeps the old start. Ending or logging an unknown label emits No such label 'x' for console.timeEnd(). Both are process warnings, shown on stderr.
Usage notes
- Time source: a monotonic high-resolution clock, so system clock changes do not affect it. The reported precision is microsecond-ish, but real accuracy is limited by JIT warmup and scheduling.
- One-off measurements lie. The first run includes compilation and cold caches; repeat the work many times or use a benchmarking tool for decisions.
- Asynchronous work: the timer measures wall-clock time from
timetotimeEnd, soawaited waiting counts. Several overlapping operations need distinct labels, for examplefetch:${id}. - Output goes to stdout. To collect the number instead, use
performance.now()orprocess.hrtime.bigint()and subtract. - Production: labels live in memory until
timeEnd; forgetting it leaks a small entry. Prefer theperf_hooksmodule for metrics. timeLog()can add context likeconsole.timeLog('job', 'rows:', rows)without stopping the timer.- Groups indent the line, because the output is an ordinary console write.