|
-
Nov 3rd, 2004, 08:24 AM
#1
Thread Starter
Frenzied Member
quickest way to measure the time in seconds and milliseconds
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
-
Nov 3rd, 2004, 09:13 AM
#2
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.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Nov 3rd, 2004, 10:15 AM
#3
Thread Starter
Frenzied Member
Does anyone really know how much effort it is in nunit to do that same thing? Perform unit testing of a function?
/Henrik
-
Nov 3rd, 2004, 11:24 AM
#4
Hyperactive Member
TickCount resolution 500 ms ?
The online help for TickCount says
The resolution of the TickCount property cannot be less than 500 milliseconds.
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
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Nov 3rd, 2004, 11:24 AM
#5
Re: TickCount resolution 500 ms ?
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
Strange...I've had readings down to 50ms
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Nov 3rd, 2004, 11:27 AM
#6
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)
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Nov 3rd, 2004, 11:57 AM
#7
PowerPoster
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.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Nov 3rd, 2004, 11:11 PM
#8
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|