8 Best Batch File Timers to Measure Time of Command
The ability to write batch commands can help a computer user to automate simple tasks without the need to learn a programming language. Windows has dozens of built in commands that perform such tasks as pinging an IP address, getting directory information, copying data, adding/editing user accounts, fixing hard disk issues, managing the wired/WiFi network, killing tasks, editing the registry, and many more.
All you have to do is launch Notepad and start writing the commands, then save the text as a file with a .bat extension. Windows will recognize it as a batch file that can be directly executed. Sometimes certain commands in the script might fail or work incorrectly. A simple solution is to measure the approximate amount of time taken to execute a command, specify a delay in between and continue with the next line.
Measuring execution time for a command line tool or the entire script can also be used for benchmarking purposes. One simple example is measuring the time taken to copy files between computers. Here we have 8 methods that you can use to track the execution time of a command or a batch script.
1. ptimeptime is a small and free tool that was released way back in 2002. It still works perfectly fine in Windows 10/11 and is a tool we’ve used before to time encodes with FFMpeg. Using ptime to measure the time to finish executing a command is as easy as adding the command and optional arguments after the filename. A slight drawback is ptime will only output seconds, so longer timed commands might be more difficult to read.
Once the task completes you will get a simple “Execution time: ***” at the end, shown in seconds. ptime claims that the measured execution time is accurate to 5 milliseconds or better although it says you shouldn’t take the thousandths digit too literally. The supplied command can also be a batch file so you can get the overall execution time of an entire script, not just a single command.
2. TimeThis
TimeThis is an official Microsoft tool from the Windows 2000 Resource Kit. Even though TimeThis is positively ancient and dates back to 1999, it still works fine on the latest versions of Windows. The TimeThis.exe executable file is installed in C:\Program Files (x86)\Resource Kit\ and the installer doesn’t set a path that allows it to run anywhere. Copy the executable to Windows or System32 to avoid continually having to type the full path.
The usage of TimeThis is pretty straightforward and you just add an external command with optional arguments to the line. The output is quite verbose with the command and start time listed first. Then the end time and elapsed time is also shown when the process has been completed.
3. Gammadyne Timer
The way Gammadyne Timer works is slightly different from the first two tools mentioned above. As the name suggests, it functions as a timer and calling the program the first time will start the timer running. Run the program again with the /s switch and the timer will stop. The result will be the elapsed time between the start and stop commands.
Timer
Run Commands
Timer /s
Above is a simple example of a batch file using Gammadyne Timer to measure the amount of time taken to run the executable. Any number of other utilities or tools can be executed in between the start and stop commands and it will simply give an overall time taken.
There are some useful command line switches for Gammadyne Timer. These include hiding the program banner, not reporting the start time, reporting elapsed time without stopping (split timer), or stopwatch mode (stop the timer on key press). Gammadyne Timer could be used in a multitude of scenarios in Windows for almost anything that you want to measure a time for.
4. TimeMem
TimeMem is ported from the Unix time utility. Instead of just showing the total time of executing a command, it also provides other information pertaining to memory usage and IO statistics such as exit code, kernel time, user time, page fault, working set, paged pool, non-paged pool, and page file size.
TimeMem requires msvcr100.dll, a Microsoft Visual C++ 2010 Redistributable file in order to run. If you don’t have it installed already, a popup will appear saying “The program can’t start because MSVCR100.dll is missing from your computer. Try reinstalling the program to fix this problem”. If that’s the case, you can download msvcr100.dll from here and place it at the same location as TimeMem.
5. TimedExec
While the other tools listed here are used in a more simplistic capacity of measuring the time taken to run a command or script, TimedExec is a little bit different. Its main purpose is to be a benchmarking tool that measures the time it takes to execute a command over several runs, then gives the results.
By default, TimedExec will first run a warmup pass and then it will run the command five times to get a result. You will get various results displayed, such as mean time, median time, confidence intervals, deviation, and fastest/slowest times, but not overall time. If you wish to run the allowed minimum of three passes with no warmup, a few environment variables need to be changed first.
Set TIMED_EXEC_PASSES=3
Set TIMED_EXEC_WARMUP_PASSES=0
Enter those into Command Prompt or a batch script before running TimedExec. A log file is also created in the same folder as the TimedExec executable.
Note that TimedExec sets its path exclusively to its own folder so directly running commands like Ping or IPConfig will require the full path. Internal DOS commands like Dir, Echo, MkDir, or Copy won’t work at all when run directly as they have no path. The obvious solution would be to run commands from a batch file, then you only have to supply the full path to the script itself.
6. Command Prompt And Batch File
There are various different ways to get an execution time for a command or script using nothing more than console commands built into Windows. Here are three different options.
Using Built In Variables
You can print the current time and date on the command line with the %TIME% and %DATE% variables. This simple method works in a similar way to Gammadyne Timer whereby you print the first time, run the command, then print the second time. The time taken to complete the operation is obviously the difference between the two.
ECHO Start Measure %Time% > timer.txt
Your Commands Here
ECHO Stop Measure %Time% >> timer.txt
This method crucially differs from Gammadyne Timer in one key area, which is the result between the two times. Here you have to work out the difference between the hours, minutes, and seconds yourself. It’s a basic rough and ready solution that probably works best with execution times of relatively short periods so it’s easier to work out the difference quickly.
Batch Script With Converted Duration Time
Another option along the same lines is a batch script that automatically converts the start and end times into a duration time. You add your own commands inside the script at the specified location and the conversion is done for you on completion.
The script still uses the before and after times of the %TIME% variable. Instead of just showing both times, it subtracts one from the other and gives the result in a readable format. Download the script with duration time, open it for editing, and enter your commands in the area indicated.
Call An External Script For Batch Files And Console Commands
As a final option, you can use a custom batch script as a command to run other scripts or single commands. It would work in a similar way to other tools above, such as ptime, while only using built in Windows commands and requires no external third party help. Use the script as follows:
TimerCmd.Bat Command {Arguments} or Script name
For the best results, it is recommended to copy the batch file to a Windows path location, such as C:\Windows or C:\Windows\System32. Then you can call TimerCmd.Bat from anywhere without having to supply a path every time. The %TIME% variable is again used to get before and after timings and the difference is calculated to get a readable result.
7. Windows PowerShell
PowerShell is a more advanced command line shell that you can find built into Windows starting from Windows 7. Like with the Command Prompt option above, you don’t need use any third party tool to measure the time to execute a command. A cmdlet called Measure-Command can be used to measure the time it takes to run a command.
Measure-Command { Command }
Do take note that it is important to wrap the command that you want to measure with left and right curly brackets or else you’ll get an invalid argument error.
Measure-Command ( Command | Out-Default }
The first command above will actually run quietly with no output while the command is running and just display the timer result. The second command will also show the output of the command in the current console window, then show the timed result when it’s finished.
8. TimeIt
Although we found two tools with the same TimeIt name, we’ll focus on the one that has a couple of extra functions. The TimeIt version from jftuga is available on GitHub and is cross platform with versions for Linux and Mac OS as well as Windows.
TimeIt Command {Arguments}
What’s interesting about this tool is it can give you a simple execution time after running a command (like ptime) or run a start and stop timer with multiple commands or a btach file in between (like Gammadyne Timer).
TimeIt _Start
Run commands or a batch script
TimeIt _End
It’s probably total overkill for most users but TimeIt is able to show time results with up to seven decimal places. The second TimeIt we found is very similar to ptime and simply shows the result time at the end of the command.
TimerBatch.zip is asking for a password.
What’s the password?
The password is on the download page or in the archive if you double click on it. Sorry, that one slipped us by…
excellent write up
Links are offline.
I checked and two are dead, thanks for the report.
The TimeThis link is dead. Please update it to the link below, or find the exe inside of it.
web.archive.org/web/20031218225021/http://download.microsoft.com:80/download/win2000platform/timethis/1.00.0.1/NT5/EN-US/timethis_setup.exe
What about some utility that shows elapsed time or progress time until the program is done executing? Not just the time it took.
Michael
They will be rare because many scripts or tools will scroll the display or the timer data will be mixed in with running commands, it would all get pretty messy.
If you are desperate to see progress just use a GUI based stopwatch and start/stop it manually. Most people don’t sit and stare at their screen while running batch scripts so there probably isn’t a great demand for what you are looking for.
Oh yeaa, I got one. I schedule backing up robots in our plant with a system of scripts. My problem is that some times the 3rd party FTP utility hangs because a robot did not reply. Maybe a cable got cut, or some times it just does not go to end of task as it should and allow the scripts to continue. I want to check to see if the task has been executing too long and if so add a message in the log file, terminate the ftp utility which will allow the script to continue to the next robot. Maybe even kick of an email to the administrator.
Thanks!
Just the information I needed!
nice tool. thanks ray
I love it!
Now we can talk in facts…
Hi Raymond,
Seems like good utilities,
Thanks for the article.
Very good!Thanks!