Commands / System

Measure-Command

Time how long a command takes

beginner System

Measure-Command
 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

ShellWhat you might type
bash / zshtime ls -R docs

More in From bash and From cmd.

Related commands