Im wondering which is the best and quickest way to measure the time it takes for a block of code to execute? Are there any best practices????
/Henrik
Printable View
Im wondering which is the best and quickest way to measure the time it takes for a block of code to execute? Are there any best practices????
/Henrik
Hi.
I would make 2 integers and use the TickCount.
VB Code:
Dim A,B as Integer A=Environment.TickCount 'Do code B=Environment.TickCount Msgbox(B-A)
This will show the time in milliseconds.
Does anyone really know how much effort it is in nunit to do that same thing? Perform unit testing of a function?
/Henrik
The online help for TickCount says
Any idea what that means?Quote:
The resolution of the TickCount property cannot be less than 500 milliseconds.
BTW the same help mentions DateTime.Ticks, which sounds like a much better way to measure time, but I can't find it.
DaveBo
Strange...I've had readings down to 50msQuote:
Originally posted by DaveBo
The online help for TickCount says
Any idea what that means?
BTW the same help mentions DateTime.Ticks, which sounds like a much better way to measure time, but I can't find it.
DaveBo
On my pc, the following code is about 75 ms when run the first time and 45 ms the rest of the times.
This is with VS2003
VB Code:
Dim A, B, C As Integer A = Environment.TickCount For C = 0 To 1000 Application.DoEvents() Next B = Environment.TickCount MsgBox(B - A)
Hi,
On my computor the following code gives a resolution of 2 milliseconds.
VB Code:
Dim d1, d2, d3 As Double Dim icount As Integer d1 = Environment.TickCount Threading.Thread.Sleep(1000) d2 = Environment.TickCount d3 = d2-d1-1000
So it looks like the MSDN article needs updating.
I believe that 500ms resolution is only in some really crappy cases. So it may or may not be the case.
Here's a class used for timing during the prime numbers contest.
http://www.mentalis.org/soft/class.qpx?id=8