Subject: Speeding up processing time on ASP file
Posted By: sswingle Post Date: 4/12/2006 9:23:14 PM
I have an ASP file that takes about 6 seconds from telling the browser to open it, to the page appearing on the screen. Its a big table that is generated from data from 2 seperate access tables. My code isn't very long, but I do realize I am looping it 73 times, one loop for each row in the table, so I expect it to be slow, but I was just wondering if there was anything I can do to it in order to speed things up a bit.

Thanks!

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <style>
    td { font-size : 8pt; font-family : Verdana, Arial; text-decoration : none; }
    body { font-size : 8pt; font-family : Verdana, Arial; text-decoration : none; }
    </style>
    <title>Breaks Page</title>
</head>

<body>
    <%
    Function pad0(n)
    If n >= 10 then
   pad0 = Cstr(n)
    else
   pad0 = "0" & Cstr(n)
    end if
    end function
    ' Declaring variables
    Dim form_id, data_source, con, rs1, sqlrecord, count, m, h, sqlrecord2, rs2, status, stime
     form_id = CInt(Request.Form("id"))
     data_source =  "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
                 Server.MapPath("breaks.mdb")
     %><table border="1" id="table1" width="661" cellspacing="0" cellpadding="0">
          <p align="left">Current Time:<%=time()%></p>
        <p align="left"><font size="2"><a href="../feedback/feedback.html">
        Questions, Comments, Suggestions?</a></font></p>
        <p align="center"><b><span style="font-size: 10pt">Breaks</span></b></p>
     <tr><td>Time<td>Status</td><td width="63">Legend:</td><td bgcolor="#FF9933">Short Break</td><td bgcolor="#3399FF">Break</td></td><td bgcolor="#FFFF00">Lunch</td></tr><%
    count=0
    m = 45
    h = 7
    
    For count=1 to 73    
    
    m = m + 15
    if m >= 60 then
       m = m - 60
       h = h + 1
    end if
    if h >= 24 then
    h = 0
    m = 0
    End If

    sTime = Cstr(h) & ":" & pad0(m)

    
     sqlrecord= "Select * FROM users WHERE slot=" & count & ";"
     sqlrecord2= "Select * FROM slots WHERE slot=" & count & " ;"
                 
    ' Creating Recordset Object and opening the database
       Set rs1 = Server.CreateObject("ADODB.Recordset")
       Set rs2 = Server.CreateObject("ADODB.Recordset")
       rs1.Open sqlrecord, data_source
       rs2.Open sqlrecord2, data_source
           %>
        <tr>
            <td height="36"><b><%response.write(sTime)%></b></td>
            <%If rs2("status")="open" then%>
            <td bgcolor="#66FF33">
            <p align="center"><b>Open</b></td>
            <%Else If rs2("status")="closed" then%>
            <td bgcolor="#FF3300">
            <p align="center"><b>Closed</b></td>
            <%End If End If%>
            <%While Not rs1.EOF
            If rs1("kind")="break" then %>
            <td width="120" bgcolor="#3399FF"><b><%=rs1("user")%></b></td>
            <%Else If rs1("kind")="lunch" then%>            
            <td width="190" bgcolor="#FFFF00"><b><%=rs1("user")%></b></td>
            <%Else%>
            <td width="143" bgcolor="#FF9933"><b><%=rs1("user")%></b></td>
            <%End If End If
             rs1.MoveNext
            Wend
            If rs2("status")="open" then%>

            <td width="54" height="36" valign="top"><form action="request.asp" method="post">
            <input type="hidden" name="slot" value="<%=rs2("slot")%>">
            <button name="B3" style="padding:-4px; width: 52px; height: 18px; font-size:8pt" type="submit">Request</button></form></td></form>
<%End If
   ' Done. Now close the Recordset
   rs1.Close
   rs2.Close
   Set rs1 = Nothing
   Set rs2 = Nothing%>
   </tr>
   <%
   Next %>
      </tr>
</div>
</body>
</html>

Reply By: sswingle Reply Date: 4/12/2006 9:57:48 PM
Well, I partially answered my own question already. I got the Set rs1 = Server.CreateObject("ADODB.Recordset") and  Set rs1 = Nothing commands outside of the loop and its running at about 2.5 seconds now.

Reply By: grstad Reply Date: 4/14/2006 4:51:08 AM
Hei sswingle!

What next does the <%next%>, line five from the bottom, display? Does not the  rs1.MoveNext see to that?

Med vennlig hilsen
grstad

PS. All questions are good questions!


Go to topic 42927

Return to index page 314
Return to index page 313
Return to index page 312
Return to index page 311
Return to index page 310
Return to index page 309
Return to index page 308
Return to index page 307
Return to index page 306
Return to index page 305