This is a very basic question…quite embarassing, but here goes:
I have a Stopwatch block in C# code. I determine the elapsed time in ticks and then want to convert to ns, ms, s. I know that the Frequency is provided by the Stopwatch class and that it is required for conversion.
Thanks
Stopwatch.Elapsed is a TimeSpan, so you can do
myStopwatch.Elapsed.TotalMilliseconds,myStopwatch.Elapsed.TotalSeconds, etc.Output:
Note that
stopwatch.ElapsedMillisecondsreturns alongand is thus only precise up to the millisecond, whilestopwatch.Elapsed.TotalMillisecondsreturns adoubleand has the same precision asstopwatch.ElapsedTicks, except it’s easier to use. ILSpy shows thatTimeSpan.TotalMillisecondsis computed using ticks anyway.