Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Performance issue - Which is faster?

Status
Not open for further replies.

xtremeLogic

Programmer
Dec 19, 2003
53
CA
Hi, I just had a quick question as to what is more efficient in terms of speed. I wanted to select a specific dropdown list item based on its value from the db. 'Dr' is the name of my SQLDataReader and 'DocType' is the value I am comparing with:

Code1:
Code:
DocType.SelectedIndex = DocType.Items.IndexOf(DocType.Items.FindByValue(DeNull(Dr("DocType"))))

or Code2:
Code:
Select Case Trim(Dr("DocType"))
    Case "CCO"
        DocType.SelectedIndex = 1
    Case "Email"
        DocType.SelectedIndex = 2
    Case "Excel"
        DocType.SelectedIndex = 3
    Case "Fax"
        DocType.SelectedIndex = 4
    Case "Letter"
        DocType.SelectedIndex = 5
    Case "Memo"
        DocType.SelectedIndex = 6
    Case "Note"
        DocType.SelectedIndex = 7
    Case "PDF"
        DocType.SelectedIndex = 8
    Case "Si"
        DocType.SelectedIndex = 9
    Case "Word"
        DocType.SelectedIndex = 10
End Select

Thanks.
 
The answer is that the timings in both cases will be so short that unless your program spends it entire life doing this it's probably irrelevant in the greater scheme of things.

However the first solution won't need to be recoded when you add another 4 values and remove 2 of the existing ones so it'll improve your performance :)
 
To satisfy your curiosity, put timing on a "massive" loop of each.

dim timestart as dateTime
dim timeMilli1 as double
dim timeMilli2 as double

timestart = Date.now
For I = 0 to 999999
....
Next
timeMilli1 = Date.Now.Subtract(timeStart).TotalMilliSeconds

timestart = Date.now
For I = 0 to 999999
....
Next
timeMilli2 = Date.Now.Subtract(timeStart).TotalMilliSeconds



Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks for the insight guys, its always good to know these things!
smiletiniest.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top