Solved

Increasing load time of algorithm

Posted on 2004-10-01
2
189 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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now