Created
November 30, 2014 01:48
-
-
Save Jaykul/1877b4417a206b74c60c to your computer and use it in GitHub Desktop.
The cost of Write-Debug when you're not debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-DebugPreference { | |
[CmdletBinding()] | |
param($count = 1e5) | |
$Counter = 0 | |
for($i = 0; $i -lt $count; $i++) { | |
if($DebugPreference -gt "SilentlyContinue") { | |
$Counter += 1 | |
Write-Debug "The Counter is $Counter" | |
} | |
} | |
} | |
function Test-WriteDebug { | |
[CmdletBinding()] | |
param($count = 1e5) | |
$Counter = 0 | |
for($i = 0; $i -lt $count; $i++) { | |
Write-Debug "The Counter is $(($Counter += 1))" | |
} | |
} | |
$DebugPreference = "SilentlyContinue" | |
Measure-Command { Test-DebugPreference } # ~ 441 ms on my hardware | |
Measure-Command { Test-WriteDebug } # ~ 5995 ms on my hardware | |
$DebugPreference = "Continue" | |
Measure-Command { Test-DebugPreference } # ~47906 ms on my hardware | |
Measure-Command { Test-WriteDebug } # ~46122 ms on my hardware |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment