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

    Hi,

    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
    STOP = FALSE
    End Sub

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

    Sub Something
    STOP = FALSE

    Do the thing.....

    STOP = FALSE
    End Sub

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

    thnx
    Marc
     
    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.

    Gary
     
  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: http://www.basic4ppc.com/forum/showthread.php?t=384
    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....
    Marc
     
Loading...