Solved

Increasing load time of algorithm

Posted on 2004-10-01
2
192 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

839 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