Most accurate timing in VB .NET??

H

Howard Kaikow

In VB, I've developed the habit of using the API QueryPerformanceCounter to
achieve the most accurate timings.

In VB .NET, one can use TotalMilliseconds and Ticks to convert time to
milliseconds.
Is this as accurate as using the QueryPerformanceCounter?

What is the resolution of Now in VB .NET?

For example:

Dim datEnd As Date
Dim datStart As Date

datStart = Now
' Do stuff here
datEnd = Now
MsgBox((datEnd.Ticks - datStart.Ticks) / 10000 & " milliseconds(Ticks)" &
vbCrLf & _
datEnd.Subtract(datStart).TotalMilliseconds.ToString() & "
milliseconds(Subtract)")
 
J

Jay B. Harlow [MVP - Outlook]

Howard,
I normally use QueryPerformanceCounter as I understand it has a sub
millisecond resolution. Plus it is the resolution of the PerformanceCounter
classes.

When Whidbey (VS.NET 2005) arrives we will have System.Diagnostics.Stopwatch
class that you can use as a high resolution timer. I understand that it will
decides which is better (higher resolution) DateTime.Ticks or
QueryPerformanceCount.

http://longhorn.msdn.microsoft.com/lhsdk/ref/ns/system.diagnostics/c/stopwatch/stopwatch.aspx


Remember the QueryPerformanceFrequency function indicates what the
resolution of the QueryPerformanceCounter function is. Ticks are at a fixed
resolution of 100-nanosecond, however I understand they may not be updated
every 100-nanoseconds...

Hope this helps
Jay
 
A

Armin Zingler

Howard Kaikow said:
In VB, I've developed the habit of using the API
QueryPerformanceCounter to achieve the most accurate timings.

In VB .NET, one can use TotalMilliseconds and Ticks to convert time
to milliseconds.
Is this as accurate as using the QueryPerformanceCounter?

What is the resolution of Now in VB .NET?

For example:

Dim datEnd As Date
Dim datStart As Date

datStart = Now
' Do stuff here
datEnd = Now
MsgBox((datEnd.Ticks - datStart.Ticks) / 10000 & "
milliseconds(Ticks)" & vbCrLf & _
datEnd.Subtract(datStart).TotalMilliseconds.ToString() & "
milliseconds(Subtract)")


http://groups.google.com/groups?selm=#[email protected]


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
A

Armin Zingler

Howard Kaikow said:
http://groups.google.com/groups?selm=#[email protected]

The article uses

Win32.QueryPerformanceCounter(Counter)

Is there a .NET library that imports the API?
Where is the Win32 object defined?


No, sorry, I forgot them:

public notinheritable class Win32
Public Declare Auto Function QueryPerformanceCounter _
Lib "kernel32.dll" (ByRef Counter As Long) As Integer
Public Declare Auto Function QueryPerformanceFrequency _
Lib "kernel32.dll" (ByRef counter As Long) As Integer

private sub new
end sub
end class




--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top