How to use timer to clock speed of subs?

Discussion in 'Questions (Windows Mobile)' started by Stellaferox, Feb 26, 2008.

  1. Stellaferox

    Stellaferox Active Member Licensed User


    I want a very simple timer to clock the speed in several subs in order to tune up the speed of the application.
    Is this enough?

    Sub Globals
    N = 10
    End Sub

    Sub App_Start
    Timer1.Interval = 1 'minimum milliseconds
    Timer1.Enabled = True
    End Sub

    Sub Something

    Do the thing.....

    End Sub

    Sub Timer1_Tick
    N = N+1
    If STOP = FALSE Then Timer1.Enabled = False
    lblTime.Text = N
    End Sub

    Last edited: Feb 26, 2008
  2. willisgt

    willisgt Active Member Licensed User

    Marc, you might do better to get the current time (in ticks) at the start of the routine, and again at the end, then take the difference of the two.

  3. Stellaferox

    Stellaferox Active Member Licensed User

    Is that not what this routine does?
  4. Erel

    Erel Administrator Staff Member Licensed User

    This will not work as the timer tick events will not fire while other code is running (unless you add the DoEvents keyword).
    Just checking the value of Now will also not be enough because it is updated each second on the device.
    The solution is to use GetTickCount from this library:
    Calculate its value in the beginning and end of each sub.
  5. Stellaferox

    Stellaferox Active Member Licensed User

    thanks Erel,
    This works great!
    This forum is a real goldmine....
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice