How to use timer to clock speed of subs?

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:

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
 

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.
 
Top