Measure-Command
Time how long a command takes
Measure-Command { Get-ChildItem -Path .\docs -Recurse }
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Measure-Command
Runs the script block and returns a TimeSpan. The command's own output is hidden; you only get the timing.
Try this
Compare two ways of doing the same thing:
(Measure-Command { Get-ChildItem -Path .\docs -Recurse -Filter *.md }).TotalMilliseconds
(Measure-Command { Get-ChildItem -Path .\docs -Recurse | Where-Object Extension -eq '.md' }).TotalMilliseconds
-Filter is usually much faster because the file system does the filtering.
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | time ls -R docs |
More in From bash and From cmd.