Timing a command's execution in PowerShell

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Timing a command's execution in PowerShell

Message par ForumBot »

Timing a command's execution in PowerShell
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Timing a command's execution in PowerShell

Message par ForumBot »

Yup.

```
Measure-Command { .\do_something.ps1 }

```

Note that one minor downside of `Measure-Command` is that you see no `stdout` output.

[Update, thanks to @JasonMArcher] You can fix that by piping the command output to some commandlet that writes to the host, e.g. `Out-Default` so it becomes:

```
Measure-Command { .\do_something.ps1 | Out-Default }

```

Another way to see the output would be to use the .NET `Stopwatch` class like this:

```
$sw = [Diagnostics.Stopwatch]::StartNew()
.\do_something.ps1
$sw.Stop()
$sw.Elapsed

```
Répondre

Revenir à « PowerShell »