Yesterday, at the end of my post, I mentioned that
displaying information on the screen can slow down processing time. It is true.
Here is a simple test.
First of all, execute this code in the ISE
Function Test-Information
{
[cmdletbinding()]
Param()
For ($X
= 0 ; $X -lt 1000; $X++)
{
Write-Information
-MessageData "The
value of X is $X"
}
Write-Information
-MessageData "Script
Complete" -InformationAction Continue
}
Next execute this line of code.
PS C:\> Measure-Command -Expression {Test-Information}
Script Complete
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 186
Ticks :
1860662
TotalDays :
2.15354398148148E-06
TotalHours :
5.16850555555556E-05
TotalMinutes :
0.00310110333333333
TotalSeconds :
0.1860662
TotalMilliseconds : 186.0662
Take note of the milliseconds. Now execute this line of code.
PS C:\> Measure-Command -Expression {Test-Information -InformationAction Continue}
Notice that we are using the –InformationAction parameter to tell PowerShell to display the
information messages. Now look at the
milliseconds in the measurement data.
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 443
Ticks :
4439468
TotalDays :
5.13827314814815E-06
TotalHours :
0.000123318555555556
TotalMinutes :
0.00739911333333333
TotalSeconds :
0.4439468
TotalMilliseconds : 443.9468
It took more than twice as long to run. Moral of the story is this. Let your user decide if they want to see the “extra”
information or just let PowerShell run and do its thing.
Comments