0

Some sub's in my VB.Net program take a lot of time, and I do not understand why. I'd like to start a counter at the beginning of the sub and write the Milliseconds passed for each row in the console.

I tried using a Timer and resetting it after each row but it was too threadintesive. Is there a better way, using the system date/time in order to get a quite precise reading of the time each step takes?

Thank you

sharkyenergy
  • 3,842
  • 10
  • 46
  • 97
  • Try [Stopwatch](https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx). You have to import `System.Diagnostics`. You want to look at methods `Start`, `Restart` and on Property `Elapsed`. – Alex B. Jul 27 '16 at 08:31

1 Answers1

0

Use the Stopwatch class. However doing so for each row seems a bit impossible... That means you would have to add for example Console.WriteLine() after every row.

Example usage:

Dim sw As New Stopwatch

sw.Start()
yourMethod()
sw.Stop()

Console.WriteLine(String.Format("{0} ms", sw.Elapsed.TotalMilliseconds))
Visual Vincent
  • 18,045
  • 5
  • 28
  • 75