Does requesting one single parameter using the method GetParameters perform less well than using the method GetParameter?
If you put a magnifying glass on it then the answers is yes, as it requires more resources.
- On SLScripting side:
- You need to construct the "new" uint[], which is present on the heap. While if Parameter.model is directly used then it doesn't need the extra item on the heap
- You need to the return object[], which is also present on the heap. One item containing the array, another item containing the string value. That then also needs to be accessed. While if the GetParameter is directly used you have direct access.
- On SLProtocol side:
- It needs to iterate over the items in the object array
- It needs to construct the result in an object array
Will the difference be noticeable? Probably not, but my personal preference would be if you only need to get 1 parameter that the GetParameter call is executed as the overhead is avoided and the code is also more readable. But if you need to retrieve more parameters then get them in one call as it reduces the inter process calls.
Hey Jens,
Just to give some more feedback/measurements to this. I did some quick tests to find out the difference between these calls. I tested the following two calls, each 1.000.000 times:
protocol.GetParameter(101)
protocol.GetParameters(new uint[]{101})
The first loop took about 21 seconds, the second one took 32 seconds.
It seems to be 30% faster to use the first call. Do note that this difference is negligible when doing a moderate amount of calls.