Results 1 to 5 of 5

Thread: Weird Question! Timing a Loop!

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question

    Hello!
    I have a question for all you!
    I was wondering how i can time a Loop like For i = 1 to 6000, i would like to time it how long it owuld take to loop threw that, but i have no idea how i am suppose to time it....does anyone else?
    if you do please post it!
    thanks for listening!

  2. #2
    Guest
    Use GetTickCount.
    Code:
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    Private Sub Command1_Click()
    
        Start = GetTickCount
        
        For I = 0 To 60000
        Next I
        
        Pause = GetTickCount
        MsgBox "It took " & Pause - Start & " milliseconds"
        
    End Sub

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    The easiest way is to use the timer keyword, this gives the number of seconds since the computer was booted (or something) accurate to 100th of a second so you could do something like this

    Code:
    Private Sub Command1_Click()
    
    
    Dim x As Single
    Dim i As Long
    
    x = Timer
    
    For i = 0 To 10000000
    
        
    Next i
    
    x = Timer - x
    
    MsgBox "The loop took " & x & " seconds."
    
    End Sub
    kedaman and others are now going to tell you about the wonders of GetTickCount and QueryPerformanceTimer, but this is good enough for modt things.

  4. #4

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Talking Cool It works!

    Thanks guys!
    See what i'm trying to do is time 1 kind of loop and then time another one to see witch one goes faster, can someone tell me another way to do the same thing but with maybe a slower way to loop threw it?
    like a differnet syntx for looping with the time and stuff included still.

    Thanks

  5. #5
    Guest
    Sam Finch: Whether or not others tell the wonders of GetTickCount and QPC is besides the point. In this case, using QPC or GetTickCount would be better because as your loops get smaller, Timer will not be able to measure it correctly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width