The time command in Linux and Unix-like operating systems is used to determine how long a specific command or script will take to run.
In Windows PowerShell there is a built-in Measure-Command, that can be considered as the Linux time command equivalent.
This short post shows how to use the Measure-Command in PowerShell to evaluate the processing time taken by different commands, scripts or programs in their execution.
Cool Tip: Windows grep command equivalent in CMD and PowerShell! Read more →
Command Execution Time in Windows PowerShell
To measure execution time of a command or script in Windows PowerShell, execute:
PS C:\> Measure-Command { command }
- example -
PS C:\> Measure-Command { netstat /f /q }
- sample output -
Days : 0
Hours : 0
Minutes : 0
Seconds : 2
Milliseconds : 25
Ticks : 20258498
TotalDays : 2.34473356481481E-05
TotalHours : 0.000562736055555556
TotalMinutes : 0.0337641633333333
TotalSeconds : 2.0258498
TotalMilliseconds : 2025.8498
The command above measures and prints the execution time, but it doesn’t print the actual output of the command or script.
To print the execution time as well as the command’s output execute:
PS C:\> Measure-Command { command | Out-Default }
- example -
PS C:\> Measure-Command { netstat /f /q | Out-Default }
The combination of Measure-Command and Out-Default prints not the execution time only but also the output of the command itself.