Skip to content

Instantly share code, notes, and snippets.

@SimonWahlin
Created January 16, 2015 20:14
Show Gist options
  • Save SimonWahlin/3c69d10a1c13aa439063 to your computer and use it in GitHub Desktop.
Save SimonWahlin/3c69d10a1c13aa439063 to your computer and use it in GitHub Desktop.
Contraproff empty pipelines
Function Init {
$File = "$env:tmp\testfile.tmp"
if(-Not (Test-Path -Path $File)){[Void](New-Item -Path $File -Type File)}
Start-Service -Name Spooler
}
Function Validate {
$File = "$env:tmp\testfile.tmp"
$FileStatus = if(Test-Path -Path $File){'Exists'}else{'Removed'}
$SrvStatus = (Get-Service -Name Spooler).Status
'{0,-7} {1}'-f $FileStatus, $SrvStatus
}
Function Measureit {
$File = "$env:tmp\testfile.tmp"
Init
$m1 = (Measure-Command -Expression {
Stop-Service -Name Spooler -Force |
Remove-Item $File |
Start-Service -Name Spooler
}).milliseconds
$r1 = Validate
$m2 = (Measure-Command -Expression {
Stop-Service -Name Spooler -Force
Remove-Item $File
Start-Service -Name Spooler
}).Milliseconds
$r2 = Validate
"Time:{0,-4}Result: {1,-17} | Time:{2,-4}Result: {3,-20}" -f $m1, $r1, $m2, $r2
}
1..20 | %{measureit}
@SimonWahlin
Copy link
Author

Results in the following:
Time:5 Result: Exists Stopped | Time:286 Result: Removed Running
Time:5 Result: Exists Stopped | Time:288 Result: Removed Running
Time:5 Result: Exists Stopped | Time:280 Result: Removed Running
Time:4 Result: Exists Stopped | Time:290 Result: Removed Running
Time:4 Result: Exists Stopped | Time:290 Result: Removed Running
Time:4 Result: Exists Stopped | Time:290 Result: Removed Running
Time:6 Result: Exists Stopped | Time:305 Result: Removed Running
Time:4 Result: Exists Stopped | Time:289 Result: Removed Running
Time:5 Result: Exists Stopped | Time:290 Result: Removed Running
Time:4 Result: Exists Stopped | Time:281 Result: Removed Running
Time:4 Result: Exists Stopped | Time:290 Result: Removed Running
Time:5 Result: Exists Stopped | Time:280 Result: Removed Running
Time:4 Result: Exists Stopped | Time:291 Result: Removed Running
Time:4 Result: Exists Stopped | Time:291 Result: Removed Running
Time:4 Result: Exists Stopped | Time:291 Result: Removed Running
Time:5 Result: Exists Stopped | Time:287 Result: Removed Running
Time:4 Result: Exists Stopped | Time:295 Result: Removed Running
Time:4 Result: Exists Stopped | Time:290 Result: Removed Running
Time:4 Result: Exists Stopped | Time:294 Result: Removed Running
Time:5 Result: Exists Stopped | Time:290 Result: Removed Running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment