ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 7th, 2008, 05:24 AM
janusz-jasinski janusz-jasinski is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2004
Location: Birmingham, UK
Posts: 520 janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 28 m 51 sec
Reputation Power: 25
Send a message via MSN to janusz-jasinski
Optimise Looping Code

Hi,

the code below works but takes a while to pull the results through. If I take the patients section out, it comes back straight away but once it's added, it takes seven seconds. There are approx 3k patient records.

Is there a quicker way of doing this?

Quote:
Call OpenDB()
sql = "EXEC spGetClusters"
Set rs = dbConn.Execute(sql)
WHILE not rs.eof
Response.Write("d.add("&i&",0,'"&rs("ClusterDesc")&"','cluster.asp?id="&rs("ClusterID")&"','','mainFrame','images/area.gif','images/area.gif');")& vbcrlf
j=i

sql = "EXEC spGetTeams "&rs("ClusterID")
Set rs2 = dbConn.Execute(sql)
WHILE not rs2.eof
i=i+1
Response.Write("d.add("&i&","&j&",'"&rs2("TeamDesc")&"','team.asp?id="&rs2("TeamID")&"','','mainFrame','images/area2.gif','images/area2.gif');")& vbcrlf
k=i

sql = "EXEC spGetClinicians "&rs2("TeamID")
Set rs3 = dbConn.Execute(sql)
WHILE not rs3.eof
i=i+1
Response.Write("d.add("&i&","&k&",'"&replace(rs3("cName"),"'","\'")&"','clinician.asp','','mainFrame','images/nurse.gif','images/nurse.gif');")& vbcrlf

l=i
sql = "EXEC spGetPatients "&rs3("ClinicianID")
Set rs4 = dbConn.Execute(sql)
WHILE not rs4.eof
i=i+1
Response.Write("d.add("&i&","&l&",'"&replace(rs4("NHSNo"),"'","\'")&"','http://www.google.co.uk','','mainFrame','images/mpatient.gif','images/mpatient.gif');")& vbcrlf
rs4.movenext()
wend
Set rs4 = Nothing

rs3.movenext()
wend
Set rs3 = Nothing

rs2.movenext()
wend
Set rs2 = Nothing

i=i+1
rs.movenext()
wend
Call CloseDB()

Reply With Quote
  #2  
Old May 7th, 2008, 12:59 PM
Spudhead Spudhead is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 146 Spudhead User rank is Corporal (100 - 500 Reputation Level)Spudhead User rank is Corporal (100 - 500 Reputation Level)Spudhead User rank is Corporal (100 - 500 Reputation Level)Spudhead User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 19 h 19 m 14 sec
Reputation Power: 7
Without seeing your actual SQL it's difficult to say for sure, but I'd be surprised if there wasn't a way you could combine those multiple SQL calls into one, that grouped the records in a way that you could loop through and produce the same output.

That would be, by far, the main performance improvement you could make. How many calls to the database is it currently making?

One other thing that would probably make a noticeable, if relatively minor, difference: don't loop through recordsets. Use getRows() to turn it into an array and loop through that. Looping through recordsets is bad, as is referencing values straight out of one. Every time you reference a value using oRs("myfieldname"), it's gotta go searching through the big, cumbersome recordset object for the value. Get values out into variables and use those.
Comments on this post
janusz-jasinski agrees: GetRows

Reply With Quote
  #3  
Old May 8th, 2008, 04:11 AM
janusz-jasinski janusz-jasinski is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2004
Location: Birmingham, UK
Posts: 520 janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 28 m 51 sec
Reputation Power: 25
Send a message via MSN to janusz-jasinski
EXEC spGetClusters : "SELECT ClusterID,ClusterDesc FROM tblCluster ORDER BY ClusterID"

EXEC spGetTeams : "SELECT TeamID,TeamDesc FROM tblTeam WHERE ClusterID=@cID ORDER BY TeamDesc"

EXEC spGetClinicians : "SELECT ClinicianID,Surname + ', ' + Forename AS cName FROM tblClinician WHERE TeamID=@tID ORDER BY Surname"

EXEC spGetPatients : "SELECT NHSNo FROM tblPatient WHERE ClinicianID=@cID"

I'll try the getRows. Thanks.

Reply With Quote
  #4  
Old May 8th, 2008, 04:33 AM
janusz-jasinski janusz-jasinski is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2004
Location: Birmingham, UK
Posts: 520 janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 28 m 51 sec
Reputation Power: 25
Send a message via MSN to janusz-jasinski
Ok - so I've used the GetRows method but it's still taking 7-8 seconds to display the results.

Ah well - thanks for your help. I learn something new everyday!

Let's say I have a table containing {NORTH, SOUTH, EAST, WEST}. I'll display this as follows {COUNTER, HEADING, NAME, ID}

1 : 0 : NORTH: 3
2 : 0 : SOUTH : 5
3 : 0 : EAST : 7
4 : 0 : WEST : 8

For each section under NORTH in another table, I have to do similar i.e.

5 : 1 : LIVERPOOL : 3
6 : 1 : MANCHESTER : 4
7 : 1 : LEEDS : 5

... and so on for 2-3 more levels... does that make sense? Then for Liverpool I'd have:

8 : 5 : KIRBY: 3
9 : 5 : PENNY LANE: 4
10 : 5 : ALLERTON: 5

Last edited by janusz-jasinski : May 8th, 2008 at 04:55 AM.

Reply With Quote
  #5  
Old May 8th, 2008, 06:16 AM
janusz-jasinski janusz-jasinski is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2004
Location: Birmingham, UK
Posts: 520 janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level)janusz-jasinski User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 28 m 51 sec
Reputation Power: 25
Send a message via MSN to janusz-jasinski
SQL runs fine.

It's when it writes over 3k lines that the process slows down!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Optimise Looping Code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway