Dear MVP - Web control performance enquiries

G

Guest

Dear MVP,

A small question to you all
Lets say I have an application which gets the value from a drop down list,
e.g.

GetProductInfo1(ddl.selectedItem.value)
GetProductInfo2(ddl.selectedItem.value)
GetProductInfo3(ddl.selectedItem.value)
GetProductInfo4(ddl.selectedItem.value)
GetProductInfo5(ddl.selectedItem.value)

If you notice, I’m repeating ddl.selectedItem.value 5 times, would it be
better if I just put it into a variable e.g.

Dim int as integer

Int = ddl.selectedItem.value

And from there I just use the variable when ever I need it, rather then
having it call this stmt ddl.selectedItem.value. would it improve performance?

Thanks for taking the time to read this post.
 
K

Ken Dopierala Jr.

Hi,

I'm not an MVP but I can answer this for you. If you are just using it 5
times you will not notice much of a performance boost by putting it into a
variable. However, if you were using this in a loop that had a ton of
iterations you would see a *small* gain in performance. Also it looks like
your GetProductInfoX() functions take an Integer. So by doing this:

Dim int as Integer
int = CInt(ddl.SelectedItem.Value)

And then using int in your function calls you will also increase performance
because the CLR won't have to perform the conversion 5 times. Again, since
it is only used 5 times the performance will hardly be measurable. But if
this was in a loop then the conversion for each iteration would cost you a
little bit.

By putting Option Strict On at the beginning of each code file you will see
where the CLR is doing all your conversions for you. If they are in loops
then doing the conversion yourself and using the result will optimize your
code. It could also help you catch tricky errors that occur when the CLR
tries to figure out what your trying to do but gets it wrong. Good luck!
Ken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top