Dear MVP - Web control performance enquiries

Discussion in 'ASP .Net' started by Guest, Sep 24, 2004.

  1. Guest

    Guest Guest

    Dear MVP,

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


    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.
    Guest, Sep 24, 2004
    1. Advertisements

  2. 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 Dopierala Jr., Sep 24, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.