[IO.Directory]::EnumerateFiles vs. Get-ChildItem
On my laptop, with a fairly random set of files, I found that
[http://IO.Directory]::EnumerateFiles
….is a lot quicker than
get-childitem
….given that all I wanted was the filename.
Here is the test I did:
11:24 [1.83] C:\powershell >measure-command {$x = [IO.Directory]::EnumerateFiles("c:\temp", "*", 'AllDirectories')} | select milliseconds
Milliseconds
------------
4
14:26 [0.02] C:\powershell >measure-command {$x = [IO.Directory]::EnumerateFiles("c:\temp", "*", 'AllDirectories')} | select milliseconds
Milliseconds
------------
2
14:26 [0.01] C:\powershell >measure-command {$x = [IO.Directory]::EnumerateFiles("c:\temp", "*", 'AllDirectories')} | select milliseconds
Milliseconds
------------
2
14:26 [0.01] C:\powershell >measure-command {$x = get-childitem -recurse "c:\temp"} | select milliseconds
Milliseconds
------------
137
14:26 [1.14] C:\powershell >measure-command {$x = get-childitem -recurse "c:\temp"} | select milliseconds
Milliseconds
------------
731
14:26 [0.74] C:\powershell >measure-command {$x = get-childitem -recurse "c:\temp"} | select milliseconds
Milliseconds
------------
628