Solved

Increasing load time of algorithm

Posted on 2004-10-01
2
191 Views
Last Modified: 2010-05-02
My program is taking way too long to load, and I wanted to see if you experts knew of a better solution to my problem.
I have a program that takes in data dynamically. Sometimes it can load fast if the data it needs to read is small, but other times it needs to read and manipulate lots of data, and that is when it is taking forever. The function I use manipulate_data runs fast, it's processing all the queries and going through all the for loops that is taking so long. Is there another alternative? For example, would pushing the data on a stack run faster?

** I can have an infinite number of groups with each group having an infinite number of items in that group. **
**This is not the actual code. Just an example of what i'm doing**

1) Read in the amount of groups SQL query to database using RDO
2) Determine the amount of items in that group:
3) Manipulate all the data items in each group, then move on to the next group

For each GroupItem in the GroupCollection
   call manipulate_data
next

Sub manipulate_data()

For Each dataItem In colItems
     
         Sql = "SELECT * DataItemValues
         
         Set rsData = rdoConnect.OpenResultset(Sql, adOpenDynamic, adLockPessimistic)
     
         Do Until rsData.EOF
     
               DataItem.ManipulateData
               DoEvents
               Sleep 100

               'Update db with current state
               Select Case DataAction
                  Case 1
                     strSql = "Update Data1 set State = 1
                  Case 2
                     strSql = "Update Data2 set State = 2
                  Case 3
                     strSql = "Update Data3 set State = 3
               End Select

               rdoScriptConnect.Execute Sql
         
           
            rsData.Update
            rsData.MoveNext
       
      Loop
     
        rsData.Close
   
Next

End Sub


**By the way, I'm goint to be out of town this weekend. I'll check this again on monday**
Thanks in advance
0
Comment
Question by:LeeHenry
2 Comments
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 250 total points
ID: 12204222
Three questions.

1.  Have you done any testing to see which part of the code is causing the slowdown?
2.  What does DataItem.ManipulateData do?
3.  Why the Sleep 100?
0
 
LVL 3

Accepted Solution

by:
redfordb earned 250 total points
ID: 12205007
1) At first glance, the sleep shouldnt be there.
2)Instead of using the DO UNTIL LOOP do the following...

   Add two new variables ie NumOfRecords and RecordLoop

   After your open set NumofRecords to the records in the dataset ie
   'Open dataset
   NumOfRecords = rsData.recordcount
   RecordLoop = 0
   While Not (RecordLoop > NumOfRecords)
        'Put your processing here...
         RecordLoop = RecordLoop + 1
   Wend
  'Continue with your code

3) Before and after each stage in your loop add a write to an output file (like a log). Then run the program and analyze the log for delays.
4) If the long delays are justified, look at putting in a progress bar or something so the user knows something is happening. It makes the wait more bearable.

   
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now