Is there a simple way to time the execution of a command in PowerShell, like the 'time' command in Linux?
I came up with this:
$s=Get-Date; .\do_something.ps1 ; $e=Get-Date; ($e - $s).TotalSeconds
But I would like something simpler like
time .\do_something.ps1
You can also get the last command from history and subtract its
EndExecutionTime
from itsStartExecutionTime
.Using Stopwatch and formatting elapsed time:
Usage Samples
Simples
then can use as
You may want to tweak the output
Measure-Command {echo "Good morning World!" | Write-Host}
Source - https://github.com/PowerShell/PowerShell/issues/2289#issuecomment-247793839
Use
Measure-Command
Example
The pipe to
Out-Host
allows you to see the output of the command, which is otherwise consumed byMeasure-Command
.Yup.
Note that one minor downside of Measure-Command is that you see no stdout output. If you want to see the output, then you can use the .NET Stopwatch object e.g.: