Measuring Command Execution Time with Windows command line

bardimin pic

Written by Bardimin

On May 30, 2022
Home » Blogs » Windows » Measuring Command Execution Time with Windows command line

In this article, Bardimin will share a that you can use to calculate the time it takes for an or command to complete .

The method is quite easy, copy the following to and save it with the name ” ExecutionTime.bat “.

@echo off
@setlocal

set start=%time%

:: Runs your command
cmd /c %*

set end=%time%
set options="tokens=1-4 delims=:.,"
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100

set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%

:: Mission accomplished
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
echo Execution time %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)

How to use

You can use the script from CMD with the command

ExecutionTime [your command]

For example, you want to calculate the execution time required by the file ” myscript.bat ” you can use the following command

ExecutionTime myscript.bat

And if you want to count the length of time you use . You can type as follows

ExecutionTime "C:\Program Files ( x86)\ Microsoft Office\root\ Office16\WINWORD.EXE"

Latest Articles

Limit Your Privacy Data Collection in Windows 11

Limit Your Privacy Data Collection in Windows 11

People are increasingly aware of their privacy due to the use of the internet and social media platforms. Windows 11 users need to understand that the operating system actively retrieves data from many web-based sources. Whenever someone establishes a connection to a...

How to Know When Your Password Was Last Changed on Windows

How to Know When Your Password Was Last Changed on Windows

One easy method to ensure the security of user accounts is to enforce policies that require periodic password changes. One way to prompt users to change their passwords is to notify them when their passwords are about to expire. While it may not always be necessary,...

17 Tips and Tricks for Customizing Windows via Registry

17 Tips and Tricks for Customizing Windows via Registry

Before you edit or modify the Windows registry, back up from that registry. Fatal errors in changing the registry can cause the operating system to not run normally. In some cases, registry damage can only be repaired by reinstalling the operating system and resulting...

Portable BloatyNosy 0.80 – Debloat and Customize Windows 11

Portable BloatyNosy 0.80 – Debloat and Customize Windows 11

BloatyNosy is a free app that lets you remove the built-in junk apps in Windows that improve your Windows performance. The application is available in portable and installer versions. If you are looking for a free Debloat tool, then you might need to try BloatyNosy...

The sequence of Windows boot processes from zero to ready

The sequence of Windows boot processes from zero to ready

Have you ever wondered how exactly the Windows boot process happens? What processes happen in the background when you press the power button until Windows is ready for you? If yes, then you are in the right place. In this article, Bardimin will explain how all these...