Federico,
I normally use QueryPerformanceCounter as its in the units used by
Performance Counters:
Something like:
Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
' set some time var
Dim start, finish, frequency As Long
QueryPerformanceFrequency(frequency)
QueryPerformanceCounter(start)
' work
QueryPerformanceCounter(finish)
Dim time As TimeSpan = TimeSpan.FromSeconds((finish - start) /
frequency)
Alternatively you can use DateTime:
' set some time var
Dim start, finish As DateTime
start = DateTime.Now
' work
finish = DateTime.Now
Dim time As TimeSpan = finish.Subtract(start)
A third alternative would be to use "Ticks"
' set some time var
Dim start, finish As Integer
start = Environment.TickCount
' work
' set second time var and comapre to get result
finish = Environment.TickCount
Dim time As TimeSpan = TimeSpan.FromMilliseconds(finish - start)
My understanding is that QueryPerformanceCounter will normally be a higher
resolution then Environment.TickCount, however QueryPerformanceCounter may
not be available.
VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnostics.Stopwatch class that will automatically
choose between QueryPerformanceCounter & Environment.TickCount...
http://lab.msdn.microsoft.com/vs2005/
http://msdn2.microsoft.com/library/ebf7z0sw.aspx
Hope this helps
Jay