Clear-Host 1..10 | ForEach-Object { "Command: output $_" "-" * 25 $test1 = { Get-ChildItem -Path C:\test -Filter 100mb.txt | Out-Null } $test2 = { Get-ChildItem -Path C:\test | Where {$_.Name -eq '100Mb.txt'} | Out-Null } $results1 = (Measure-Command -Expression $test1).Ticks $results2 =(Measure-Command -Expression $test2).Ticks "{0}`t`t{1}" -f '-filter',$results1 "{0}`t`t`t{1}" -f 'Where',$results2 "" "{0}`t`t{1:N}" -f 'Difference',($results1/$results2) "" }
"Command: output 1" "-" * 25 $test1 = { 1..1000 | % { 1 } } $test2 = { for($i = 1; $i -le 1000; $i++) { 1 }} $results1 = (Measure-Command -Expression $test1).Ticks $results2 =(Measure-Command -Expression $test2).Ticks "{0}`t`t{1}" -f 'foreach',$results1 "{0}`t`t`t{1}" -f 'for',$results2 "" "{0}`t`t{1:N}" -f 'Difference',($results1/$results2) "" "Command: evaluate 1 -eq 1" "-" * 25 $test3 = { 1..1000 | % { 1 -eq 1 } } $test4 = { for($i = 1; $i -le 1000; $i++) { 1 -eq 1 }} $results3 = (Measure-Command -Expression $test3).Ticks $results4 =(Measure-Command -Expression $test4).Ticks "{0}`t`t{1}" -f 'foreach',$results3 "{0}`t`t`t{1}" -f 'for',$results4 "" "{0}`t`t{1:N}" -f 'Difference',($results3/$results4)
Command: output 1 ------------------------- foreach 903091 for 18212 Difference 49.59 Command: evaluate 1 -eq 1 ------------------------- foreach 907313 for 22254 Difference 40.77
if(1 -eq $true) { Do-Something }
if(1) { Do-Something }
$test_001 = { if(1 -eq $true) {1} else {0}} $test_002 = { if(1) {1} else {0}} Get-ChildItem variable:\test_* | ForEach-Object { Measure-Command -Expression {1..100000 | % { $_ }} | select TotalSeconds } TotalSeconds ------------ 12.1220562 11.732413