General testing favors MCND's command when run against several systems
Results over 1000 Runs:
Summary
P/VM - OS - PS Ver - Files - Winner - Faster By % Seconds - Winner FPS - Loser FPS (Files Per Second)
---- - ----------- - ------ - ------ - ------ - ------------------- - ---------- - ----------------------------
PM - Win 7 - 5.1.1 - 87894 - SysIO - 9% (0.29s) - 27,237 FPS - 24,970 FPS
PM - Win 2012 - 5.1.1 - 114968 - MCND - 8% (0.38s) - 25,142 FPS - 23,226 FPS
VM - Win 2012 - 5.1.1 - 99312 - MCND - 34% (1.57s) - 21,265 FPS - 15,890 FPS
PM - Win 2016 - 5.1.1 - 102812 - SysIO - 2% (0.12s) - 20,142 FPS - 19,658 FPS
VM - Win 2012 R2 - 4.0 - 98396 - MCND - 29-34% (1.56-1.71s) - 19,787 FPS - 14,717 FPS
PM - Win 2008 R2 - 5.0.1 - 46557 - MCND - 13-17% (0.33-0.44s) - 18,926 FPS - 16,088 FPS
VM - Win 2012 R2 - 4.0 - 90906 - MCND - 22% (1.25s) - 16,772 FPS - 13,629 FPS
Additionally Theos command will bomb on C:\Windows while MCND's works as expected.
-- I have explained to MK in the comments that the \cookies directory and other such directories are intentionally non-traversable so that you od not double-count the files contained within them.
The test MK ran on a VMWare fusion running atop his MAC OS is far from conclusive, and shows execution times are incredibly slow which immediately tipped me off that they were strange results.
In addition, I could not execute the command as written by MK and receive a result of the number of files in the folder, so I have included a snippet in my testing which shows all methods used do give the correct result.
Here is the code used for my runs, note I also ran 1000 runs using MK's preferred method to compare output.
Strangely that one .count method for the MCND command seems to give very biased results on my win7 system, very different from any other system and hugely slower (5x slower) in the initial runs I posted, and varying the most on future runs I tried.
But I think this is due to load, and plan to drop those results if I ever bother to post more, but most of the remaining systems are pretty similar to the results I feel like they could seem redundant if they aren't from very different systems.
$MaxRuns=1000
$Root_Dir="c:\windows\winsxs"
$Results_SysIO=@()
$Results_MCND1=@()
$Results_MCND2=@()
$Results_MCND3=@()
$Results_Meta=@()
FOR ($j=1; $j -le $MaxRuns; $j++) {
Write-Progress -Activity "Testing Mthods for $MaxRuns Runs" -Status "Progress: $($j/$MaxRuns*100)% -- Run $j of $MaxRuns" -PercentComplete ($j/$MaxRuns*100)
# Tests SysIO: @([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count
$Results_SysIO+=Measure-Command { @([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count }
sleep -milliseconds 500
# Tests MCND1 CMD Script: DIR "%~1" /s /a-d ^| FIND /I /V "" | find /c /v ""
$Results_MCND1+=Measure-Command {C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir}
sleep -milliseconds 500
# Tests MCND2 CMD Count: {cmd /c 'dir /s /b /a-d $Root_Dir | find /c /v """"'}
$Results_MCND2+=Measure-Command {cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`"}
sleep -milliseconds 500
# Tests MCND3 PS Count (cmd /c dir /s /b /a-d $Root_Dir).Count
$Results_MCND3+=Measure-Command {(cmd /c dir /s /b /a-d $Root_Dir).Count}
sleep -milliseconds 500
}
$CPU=Get-WmiObject Win32_Processor
""
"CPU: $($($CPU.name).count)x $($CPU.name | select -first 1) - Windows: $($(Get-WmiObject Win32_OperatingSystem).Version) - PS Version: $($PSVersionTable.PSVersion)"
ForEach ($Name in "SysIO","MCND1","MCND2","MCND3") {
$Results_Meta+=[PSCustomObject]@{
Method=$Name
Min=$($($(Get-Variable -Name "Results_$Name" -valueOnly).TotalSeconds|Measure-Object -Minimum).Minimum)
Max=$($($(Get-Variable -Name "Results_$Name" -valueOnly).TotalSeconds|Measure-Object -Maximum).Maximum)
Avg=$($($(Get-Variable -Name "Results_$Name" -valueOnly).TotalSeconds|Measure-Object -Average).Average)
}
}
$Results_Meta | sort Avg | select Method,Min,Max,Avg,@{N="Factor";e={("{0:f2}" -f (([math]::Round($_.Avg / $($Results_Meta | sort Avg | select Avg)[0].avg,2,1))))}}|FT
Time-Command `
{cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`"},
{C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir},
{@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count},
{(cmd /c dir /s /b /a-d $Root_Dir).Count} $MaxRuns `
""
"Results of Commands - (How many Files were in that Folder?):"
[PSCustomObject]@{
SysIO=$(&{ @([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count })
MCND1=$(&{C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir})
MCND2=$(&{cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`"})
MCND3=$(&{(cmd /c dir /s /b /a-d $Root_Dir).Count})
}
I have Additional Runs I didn't collect yet from additional systems, the Win7 Results are inconsistent though so I'll probably strip them when I have more to add to the list from other systems.
Detailed Findings
Physical Win 7 Laptop - 87894 Files - Loser: MCND is 9% (.29s) Slower - (Winning Method: 27,237 FPS) -- Results are not consistent on re-runs while other systems are.
CPU: 1x Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz - Windows: 6.1.7601 - PS Version: 5.1.14409.1012
CPU: 1x Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz - Windows: 6.1.7601 - PS Version: 5.1.14409.1012
Method Min Max Avg Factor
------ --- --- --- ------
SysIO 3.0190345 6.1287085 3.2174689013 1.00
MCND1 3.3655209 5.9024033 3.5490564665 1.10
MCND3 3.5865989 7.5816207 3.8515160528 1.20
MCND2 3.7542295 7.5619913 3.9471552743 1.23
3.2174689013
0.0000366062
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 3.227 00:00:03.2271969 1.00
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 3.518 00:00:03.5178810 1.09
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 3.911 00:00:03.9106284 1.21
(cmd /c dir /s /b /a-d $Root_Dir).Count 16.338 00:00:16.3377823 5.06
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
87894 87894 87894 87894
Physical Win 2012 Desktop - 114968 Files - Loser: SysIO is 8% (.38s) Slower - (Winning Method: 25,142 FPS)
CPU: 1x Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1012
CPU: 1x Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1012
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 4.4957173 8.6672112 4.5726616326 1.00
MCND3 4.6815509 18.6689706 4.7940769407 1.05
SysIO 4.8789948 5.1625618 4.9476786004 1.08
MCND2 5.0404912 7.2557797 5.0854683543 1.11
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 4.542 00:00:04.5418653 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 4.772 00:00:04.7719769 1.05
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 4.933 00:00:04.9330404 1.09
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 5.086 00:00:05.0855891 1.12
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
114968 114968 114968 114968
VM Win 2012 Server - 99312 Files - Loser: SysIO is 34% (1.57s) Slower - (Winning Method: 21,265 FPS)
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1005
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1005
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 4.5563908 5.2656374 4.6812307177 1.00
MCND3 4.6696518 5.3846231 4.9064852835 1.05
MCND2 5.0559205 5.5583717 5.15425442679999 1.10
SysIO 6.036294 6.7952711 6.254027334 1.34
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 4.669 00:00:04.6689048 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 4.934 00:00:04.9336925 1.06
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 5.153 00:00:05.1532386 1.10
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 6.239 00:00:06.2389727 1.34
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
99312 99312 99312 99312
Physical Win 2016 Server - 102812 Files - Loser: MCND is 2% (0.12s) Slower - (Winning Method: 20,142 FPS)
CPU: 2x Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz - Windows: 10.0.14393 - PS Version: 5.1.14393.2608
CPU: 2x Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz - Windows: 10.0.14393 - PS Version: 5.1.14393.2608
Method Min Max Avg Factor
------ --- --- --- ------
SysIO 5.0414178 5.5279055 5.1043614001 1.00
MCND3 5.0468476 5.4673033 5.23160342460001 1.02
MCND1 5.1649438 5.6745749 5.26664923669999 1.03
MCND2 5.3280266 5.7989287 5.3747728434 1.05
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 5.156 00:00:05.1559628 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 5.256 00:00:05.2556244 1.02
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 5.272 00:00:05.2722298 1.02
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 5.375 00:00:05.3747287 1.04
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
102812 102812 102812 102812
VM Win 2012 R2 Server - 98396 Files - Loser: SysIO 29-34% (1.56-1.71s) Slower - (Winning Method: 19,787 FPS)
CPU: 2x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
CPU: 2x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 4.7007419 5.9567352 4.97285509330001 1.00
MCND2 5.2086999 6.7678172 5.4849721167 1.10
MCND3 5.0116501 8.7416729 5.71391797679999 1.15
SysIO 6.2400687 7.414201 6.6862204345 1.34
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root... 5.359 00:00:05.3592304 1.00
cmd /c `"dir /s /b /a-d $Root_Dir `| ... 5.711 00:00:05.7107644 1.07
(cmd /c dir /s /b /a-d $Root_Dir).Count 6.173 00:00:06.1728413 1.15
@([System.IO.Directory]::EnumerateFil... 6.921 00:00:06.9213833 1.29
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
98396 98396 98396 98396
Physical Win 2008 R2 Server - 46557 Files - Loser: SysIO 13-17% (0.33-0.44s) Slower - (Winning Method: 18,926 FPS)
CPU: 2x Intel(R) Xeon(R) CPU 5160 @ 3.00GHz - Windows: 6.1.7601 - PS Version: 5.0.10586.117
CPU: 2x Intel(R) Xeon(R) CPU 5160 @ 3.00GHz - Windows: 6.1.7601 - PS Version: 5.0.10586.117
Method Min Max Avg Factor
------ --- --- --- ------
MCND3 2.2370018 2.8176253 2.4653543378 1.00
MCND1 2.4063578 2.8108379 2.5373719772 1.03
MCND2 2.5953631 2.9085969 2.7312907064 1.11
SysIO 2.7207865 30.335369 2.8940406601 1.17
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
(cmd /c dir /s /b /a-d $Root_Dir).Count 2.500 00:00:02.5001477 1.00
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 2.528 00:00:02.5275259 1.01
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 2.726 00:00:02.7259539 1.09
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 2.826 00:00:02.8259697 1.13
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
46557 46557 46557 46557
VMWare Win 2012 R2 Server - 90906 Files - Loser: SysIO 23% (1.25s) Slower - (Winning Method: 15,722 FPS)
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 5.0516057 6.4537866 5.423386317 1.00
MCND3 5.3297157 7.1722929 5.9030135773 1.09
MCND2 5.5460548 7.0356455 5.931334868 1.09
SysIO 6.2059999 19.5145373 6.6747122712 1.23
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root... 5.409 00:00:05.4092046 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 5.936 00:00:05.9358832 1.10
cmd /c `"dir /s /b /a-d $Root_Dir `| ... 6.069 00:00:06.0689899 1.12
@([System.IO.Directory]::EnumerateFil... 6.557 00:00:06.5571859 1.21
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
90906 90906 90906 90906