A lot of times we need to know how long a process takes. The simple way to do this is
dim startDate as DateTime = DateTime.Now
' do work
dim elapsed as TimeSpan = startDate.Subtract(DateTime.Now)
Console.WriteLine(elapsed.TotalMilliseconds)
For a general sense of time this works fine but this is not entirely accurate. DateTime.Now pulls from a lower frequency clock and can be off by milliseconds (or more).
To use a highly accurate timing MS introduced the stopwatch class in .NET 2.0. This class polls the high frequency clock to get accurate timings:
dim timer as Stopwatch = Stopwatch.StartNew
'do work
timer.Stop()
console.WriteLine(timer.ElapsedMilliseconds)
Another thing you can do is call Start() and Stop() on the timer multiple times and it will still keep summing up the time elapsed (just like a regular stopwatch).