Overheads getting a member

A while ago I wrote a blogentry about different ways of obtaining the hostname. When I wrote that one I thought wonder how the different way of accessing the member values increases the cost. So this is a blogentry about that. There are different overheads depending on how you get your objects member. To illustrate this I have made a simple single WMI query and saved in a variable, from which we will now get the name of the computer.

First lets get the WMI object:

So now we have the wmi object in the variable $wmics. So how do we get the name. Well here there are a few ways all giving the same answer.

All of those return the same information, Well if you dont really believe they are really the same lets get the type of all returned objects.

Everyone of them return the following:

Benchmarking

So now we know that we get the same answer from all lets see how long time they take:

This will give

Command Avg Ticks
.Membername 1040
Select -Expand 1145
.GetPropertyValue() 2946

So as we see some ways of obtaining member values can cost many more CPU cycles than others.

Leave a Reply