![]() |
|
|
Published: Thursday, December 02, 1999 By Mike Shaffer When referencing recordset values in your code, you probably write something like this:
There is a second way to write this code, by fully qualifying the recordset and field object references:
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
Note: Since the fields in the Here are some sample benchmarks for three runs using each method (not done under a controlled environment, but close enough to prove the point!):
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.
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!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||