dim Timer1 , Timer1.Start , run MyProcedure, Timer1.stop, how do i see how long the procedure took?

hi, i want to time how long a procedure or sub or function takes to execute.
this is what i did so far, how can i get the value of timer1 to see how long timer1 ran for?

        Dim timer1 As New Timer
        timer1.Interval = 500
        timer1.Start()
          MyProcedure
        timer1.Stop()

thanks!
jxhardingAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RonaldBiemansConnect With a Mentor Commented:
Don't use a timer for that just use the tickcount

dim int as integer = environment.tickcount
          MyProcedure

msgbox(environment.tickcount - int)


it gives the time in milliseconds
0
 
monosodiumgConnect With a Mentor Commented:
The Timer object is more of an alarm clock than a stopwatch. It will trigger an event every Interval milliseconds from when you call Start to when you call Stop.
You can use it for timing but that's not what it's usually used for.
To time your proc, simply record the system time before and after and take the difference:

Dim OldTime As Date = Now
MyProcedure
Dim NewTime As Date = Now
Dim DifferenceInSeconds As Long = DateDiff(DateInterval.Second, OldTime, NewTime)
0
 
jxhardingAuthor Commented:
much better avenue of thought
thank you both!
0
All Courses

From novice to tech pro — start learning today.