Purpose: | TIMER is a system stopwatch |
Format: | TIMER [/1 /2 /3 /4 /5 /6 /7 /8 /9 /10 /C /L /M /N /Q /S] [ON | OFF] [command] |
ON | Force the stopwatch to reset and start |
OFF | Force the stopwatch to stop |
command | Time the specified command |
stopwatch #1 (default) |
clear on ^C |
||
stopwatch #2 |
milliseconds |
||
stopwatch #3 |
microseconds |
||
stopwatch #4 |
nanoseconds |
||
stopwatch #5 |
quiet |
||
stopwatch #6 |
split |
||
stopwatch #7 |
|||
stopwatch #8 |
|||
stopwatch #9 |
|||
stopwatch #10 |
Usage:
The TIMER command accepts its parameters in any order, and acts on the specified one of ten possible timers (system stopwatches) by turning it on or off, or by displaying its current elapsed time. The TIMER command with neither of the keywords ON and OFF nor the /S option toggles the state of the timer.
TIMER uses the Windows performance counters for greater accuracy. The default TIMER resolution is in milliseconds (.001 seconds).
The switch arguments (/1 - /10, /Q, and /S) must appear before any other arguments on the TIMER command line.
If you execute TIMER or TIMER /S when the timer is off, or execute TIMER ON at any time, the current time of day is displayed, and the stopwatch starts from :
[c:\] timer
Timer 1 on: 12:21:46
If you execute TIMER /S when the timer is on, the elapsed time is displayed:
[c:\] timer /s
Timer 1 Elapsed time: 0:00:12.06
If you execute TIMER when it is on, or execute TIMER OFF, the stopwatch stops, the current time and the elapsed time are displayed, and the elapsed time is reset:
[c:\] timer
Timer 1 off: 12:21:58
Elapsed time: 0:00:12.06
There are ten stopwatches available (1 - 10) so you can time multiple overlapping events. By default, TIMER uses stopwatch #1.
TIMER is particularly useful for timing events in batch files. For example, to time both an entire batch file, and an intermediate section of the same file, you could use commands like this:
rem Turn on timer 1
timer
rem Do some work here
rem Turn timer 2 on to time the next section
timer /2
rem Do some more work
echo Intermediate section completed
rem Display time taken in intermediate section
timer /2
rem Do some more work
rem Now display the total time
timer
You can optionally specify a command for TIMER to run. This is the equivalent of "timer on & command & timer off". For example:
timer dir c:\ /s
The smallest interval TIMER can measure depends on the operating system you are using, your hardware, and the interaction between the two. However, it should never be more than 60 ms.
You can also retrieve the elapsed time of a timer using the @TIMER[] function.
Options:
/S | Display a split time without stopping the timer. To display the current elapsed time but leave the timer running: |
[c:\] timer /s
Timer 1 elapsed: 0:06:40.63
ON | Start the timer regardless of its previous state (on or off). Otherwise the TIMER command toggles the timer state (unless /S is used). |