Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Returning an ADO Recordset


Message #1 by Mitchell Spruill <MSpruill@M...> on Mon, 22 Jan 2001 18:12:30 -0500
I just ran a couple of very basic tests, and I found something interesting.

When you only need one or two items, looping through the recordset seems a 
bit faster. However, this advantage disappears when the number of items you 
need from the recordset grows.

A small example (in ASP, but the basics are the same) follows. In this 
example I retrieve elements 0, 1 and 2 from the recordset and from the array.
When I retrieve all 3 elements, the GetRows() solution is faster. When I 
only retrieve 1 element, the loop is faster. I think that means that the 
overhead of creating the two dimensional array is eventually smaller than 
the overhead of referencing multiple fields from the recordset.
I know that the retrieval of the value of the recordset 
(rsTest.Fields.Item(0)) can be optimized as well, but I haven't tested that 
yet.
OpenRecordset just opens a recordset which is dimmed in the same page,


Imar

<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">
function GetTimeInMillis()
{
         //returns date/time in milliseconds. From http://www.aspnl.com/
         var d = new Date();
         return d.getTime();
}
</SCRIPT>


<%
Dim sStart
Dim sEnd
Dim rsTest
Dim connTest
Dim iLoop

' Get data from GetRows()
sStart = GetTimeInMillis()
for iLoop = 0 to 100
         Call OpenRecordset
         if not rsTest.EOF then
                 Dim arrTest
                 arrTest = rsTest.GetRows()
                 rsTest.Close
                 Dim sHTML1
                 Dim i1
                 Dim iUBound
                 iUBound = (UBound(arrTest, 2))
                 for i1 = 0 to iUBound
                         sHTML1 = sHTML1 & arrTest(0, i1) & "<BR>"
                         sHTML1 = sHTML1 & arrTest(1, i1) & "<BR>"
                         sHTML1 = sHTML1 & arrTest(2, i1) & "<BR>"
                 next
         end if
         sEnd = GetTimeInMillis()
next
'Response.Write(sHTML1 & "<BR><BR>")
Response.Write "Difference is " & sEnd - sStart & "<BR>"


' Get data from a loop
sStart = GetTimeInMillis()
for iLoop = 0 to 100
         Call OpenRecordset
         if not rsTest.EOF then
                 Dim i2
                 Dim sHTML2
                 do while not rsTest.EOF
                         sHTML2 = sHTML2 & rsTest.Fields.Item(0) & "<BR>"
                         sHTML2 = sHTML2 & rsTest.Fields.Item(1) & "<BR>"
                         sHTML2 = sHTML2 & rsTest.Fields.Item(2) & "<BR>"
                         rsTest.MoveNext
                 loop
         end if
         rsTest.Close
         sEnd = GetTimeInMillis()
next
'Response.Write(sHTML2 & "<BR><BR>")
Response.Write "Difference is " & sEnd - sStart & "<BR>"




At 01:31 PM 1/24/2001 -0700, you wrote:
>It sounds to me like populating a two-dimensional array is cumbersome unless
>you plan on re-using the results. It only gets worse, of course, as the
>table grows.
>
>If Recordcount is not reliable (I've never had a problem with it, but
>there's always a first) and you're only going to cycle through the table
>once, I am guessing that EOF is the best way to do it.


  Return to Index