J
Jeff Jarrell
I am unable to add up two timespans as created by the
System.Diagnostics.Stopwatch class.
Each stopwatch should be about two seconds and is appears ok, but when I try
and add them up it goes to heck. I need to keep sum totals and do avgs and
things.
Here is the result of the following NUnit test. I'd hope it to be a little
closer than that.. Aargh.
Timer1: 00:00:02.0002204
Timer2: 00:00:01.9995021
Sum: 00:00:01.4317187 <-------
Thanks,
jeff
<Test()> Public Sub StopwatchTest()
Dim myStopwatch As New Stopwatch
myStopwatch.Start()
System.Threading.Thread.Sleep(2000)
myStopwatch.Stop()
Dim myStopwatch2 As New Stopwatch
myStopwatch2.Start()
System.Threading.Thread.Sleep(2000)
myStopwatch2.Stop()
Debug.WriteLine("Timer1: " & myStopwatch.Elapsed.ToString)
Debug.WriteLine("Timer2: " & myStopwatch2.Elapsed.ToString)
Dim sumElapsedTime As New TimeSpan(myStopwatch.ElapsedTicks +
myStopwatch2.ElapsedTicks)
Debug.WriteLine(" Sum: " & sumElapsedTime.ToString)
End Sub
System.Diagnostics.Stopwatch class.
Each stopwatch should be about two seconds and is appears ok, but when I try
and add them up it goes to heck. I need to keep sum totals and do avgs and
things.
Here is the result of the following NUnit test. I'd hope it to be a little
closer than that.. Aargh.
Timer1: 00:00:02.0002204
Timer2: 00:00:01.9995021
Sum: 00:00:01.4317187 <-------
Thanks,
jeff
<Test()> Public Sub StopwatchTest()
Dim myStopwatch As New Stopwatch
myStopwatch.Start()
System.Threading.Thread.Sleep(2000)
myStopwatch.Stop()
Dim myStopwatch2 As New Stopwatch
myStopwatch2.Start()
System.Threading.Thread.Sleep(2000)
myStopwatch2.Stop()
Debug.WriteLine("Timer1: " & myStopwatch.Elapsed.ToString)
Debug.WriteLine("Timer2: " & myStopwatch2.Elapsed.ToString)
Dim sumElapsedTime As New TimeSpan(myStopwatch.ElapsedTicks +
myStopwatch2.ElapsedTicks)
Debug.WriteLine(" Sum: " & sumElapsedTime.ToString)
End Sub