7 Ways to Measure Time Taken to Complete a Batch File or Command Line Execution
The ability to write batch commands will greatly help a computer user to automate simple tasks without the need to learn a programming language to write a dedicated program for it or to even install the bulky development software such as Microsoft Visual Studio. All you need to do is launch Notepad and start writing the commands, then saving it with a .bat extension where Windows operating system will automatically recognize that it is a batch file.
Running the .bat file will instantly trigger to run the multiple commands in order but sometimes certain commands can fail when they are run too closely to each other. A simple solution is to measure the approximate amount of time taken to completely execute a command, specifying a delay in between and continuing with the next line.
Apart from that, getting an execution time for a command line can also be used for benchmarking purposes. Some examples are measuring the time taken to copy files between computers, or hard drives. Here we have 7 different methods that you can use to track the execution time of a command.
1. ptimeptime is a small and free tool that was released back in 2002 but still works perfectly in Windows 8.1. Using ptime to measure the amount of time to finish executing a command is as easy as adding the command after the filename. The example command below will measure the amount of time taken to list all files and folders from C:\ drive.
ptime.exe dir C:\ /s
ptime claims that the measured execution time is accurate to 5 millisecond or better.
2. TimeThis
TimeThis is an official Microsoft tool from the Windows 2000 Resource Kit. TimeThis is a very old program released back in year 2000 but still works fine in Windows 8.1. The TimeThis.exe executable file is installed in C:\Program Files\Resource Kit\ and the installer doesn’t set a path that allows the TimeThis.exe tool to be ran anywhere so make sure you change to the Resource Kit directory to run TimeThis.
The usage of TimeThis is exactly the same as ptime. Simply append the command after timethis to measure the time to run the command.
3. Gammadyne Timer
The usage of Gammadyne Timer is slightly different than the first two tool mentioned above. It functions as a timer whereby calling the program the first time will start the timer and running it again with a /s switch will stop timer and report the measured elapsed time. Below is an example of a batch file using Gammadyne Timer to count the amount of time taken to complete executing the io.exe test file.
timer.exe
io.exe
timer.exe /s
Gammadyne Timer only shows up to decisecond while ptime and timethis shows up to milliseconds.
4. TimeMem
TimeMem is a much newer application that 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 C runtime library file in order to run or else it would show an error popup saying “The program can’t start because MSVCR100.dll is missing from your computer. Try reinstalling the program to fix this problem”. If you do not have the file, you can download from here and place it at the same location as TimeMem.
5. PowerShell
PowerShell is a more advanced command line shell that you can find built-in to Windows starting from 7 so there is no need to use any third party tool to measure the time to execute a command. A cmdlet Measure-Command can be used to measure the time it takes to run a command.
Measure-Command { .\io.exe }
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.
6. Ultra Precision Command Timer
Ultra Precision Command Timer is the oldest tool in this category that you can find dated back to 1993 and was created to measure execution time of DOS commands. Running it on Windows 8.1 will prompt you to install a legacy component NTVDM because this tool is a 16-bit application but it still works, but not on 64-bit operating system.
You’d be surprised that this old tool is the only one that can measure up to microseconds!
Download Ultra Precision Command Timer
7. %TIME%
Some people would have forgotten that you can actually print the current time and date in command line or DOS with %TIME% and %DATE%. This method would work quite similarly to Gammadyne Timer by printing the current time before and after running the command and save the time to an external timer.txt file.
ECHO Start Measure %Time% >> timer.txt
YOUR COMMAND
ECHO Stop Measure %Time% >> timer.txt
The only problem is you have to manually calculate the time differences between the two from the timer.txt file to get the total time to execute the command.
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!