Running Test-Connection
with an IP address takes considerably longer than running the same command with the server's hostname.
However; if I add the -quiet
parameter then performance is roughly the same (IP is a fraction faster, as you may expect).
Using Measure-Command
this anomaly does not show up; presumably some quirk of the output not being displayed.
The below code more accurately reflects the anomaly seen:
$begin=(get-date).ticks;test-connection '123.45.67.89'; $a=((get-date).ticks - $begin)
$begin=(get-date).ticks;test-connection 'MyHostName'; $b=((get-date).ticks - $begin)
$a-$b
Colleagues have reproduced the same issue on their machines.
Question: is anyone aware of what may cause this? i.e. I suspect it's a bug (and have reported it as such), but it implies that there's something clever going on where PowerShell may work differently depending on whether output is to be displayed or not / causing a quantum-like effect; so it's not just running the commands given in order, but is doing some (de)optimisation under the covers.
My Environment
OS: MS Windows 7 Pro SP1
$PSVersionInfo
:
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18444
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
MS Connect Bug
https://connect.microsoft.com/PowerShell/feedbackdetail/view/1578010/test-connection-performance-with-ip-and-output