When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs



















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Finance Developer (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

Published: Thursday, December 02, 1999

Optimizing ADO Calls
By Mike Shaffer


When referencing recordset values in your code, you probably write something like this:

- continued -

If rs("QuantityOrdered") < 1 then NoSale = True

There is a second way to write this code, by fully qualifying the recordset and field object references:

If rs.Fields("QuantityOrdered").Value < 1 then NoSale = True

If you refer to recordset values in your code quite a bit (and most of us do), there is a way to improve performance tremendously with very little effort. Here's the secret: when referring to recordset elements, use the ordinal form. This removes the requirement for a pseudo-dictionary lookup on the fieldname. That would mean our sample above would look like this (assuming that the field QuantityOrdered was the 13th field in our recordset):

If rs(12) < 1 then NoSale = True

Note: Since the fields in the Recordset object are ordered with their index beginning at zero, rs(12) will get the 13th element!

Here are some sample benchmarks for three runs using each method (not done under a controlled environment, but close enough to prove the point!):

Form: rs("fieldname") rs.Fields("fieldname").Value rs(x)
Results:
(in seconds)
2.967 2.936 1.650
  2.824 2.914 1.611
  2.893 2.943 1.613
Average: 2.895 2.931 1.625

Now, you may say that using the ordinal notation decreases code readability, and I would agree. Several readers have been anxious to point out that you can use constants to refer to recordset elements. Although this has a very slight performance penalty in terms of script size and initial interpreter processing, it represents a nice trade-off between code readability and efficiency, e.g.

const fldQuantityOrdered = 12 ... if rs(fldQuantityOrdered) < 1 then Nosale = True

This also has the added benefit of making changes to your code easier should your recordset ordinal positions change.

Remember, when it comes to optimizing your code for a high-volume website, be prepared and even anxious to try (and test) several techniques to obtain the desired effect. Remember that when it comes to code optimization, in some cases, the LEAST intuitive answer is the correct one.

Happy Programming!

  • By Mike Shaffer


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article