public void ConvertTime() { HighResolutionTimer timer = new HighResolutionTimer(); timer.Start(); Wait(); timer.Stop(); double duration = timer.Duration(1); Assert.Between( HighResolutionTimer.TimeToMilliseconds(duration), duration * TimeToMilliseconds * (1.0 - Variation), duration * TimeToMilliseconds * (1.0 + Variation) ); Assert.Between( HighResolutionTimer.TimeToSeconds(duration), duration * TimeToSeconds * (1.0 - Variation), duration * TimeToSeconds * (1.0 + Variation) ); Assert.Between( HighResolutionTimer.TimeToTimeSpan(duration).TotalSeconds, duration * TimeToSeconds * (1.0 - Variation), duration * TimeToSeconds * (1.0 + Variation) ); }
public void MeasureCallTime() { // Warm up HighResolutionTimer.Sample(); TimerSample start = HighResolutionTimer.Sample(); TimerSample end = HighResolutionTimer.Sample(); Console.WriteLine(HighResolutionTimer.Duration(start, end)); HighResolutionTimer timer = new HighResolutionTimer(); timer.Start(); timer.Stop(); Console.WriteLine(timer.Duration(1)); }
public void MultipleSamples() { HighResolutionTimer timer = new HighResolutionTimer(); TimerSample sample1 = HighResolutionTimer.Sample(); double elapsedTime1 = Wait(); TimerSample sample2 = HighResolutionTimer.Sample(); double elapsedTime2 = Wait(); TimerSample sample3 = HighResolutionTimer.Sample(); double duration1 = HighResolutionTimer.Duration(sample1, sample2) * TimeToMilliseconds; Console.WriteLine("1 -> DateTime time: {0:N3}, Timer time: {1:N3}", elapsedTime1, duration1); Assert.Between( duration1, elapsedTime1 * (1.0 - Variation), elapsedTime1 * (1.0 + Variation) ); double duration2 = HighResolutionTimer.Duration(sample2, sample3) * TimeToMilliseconds; Console.WriteLine("2 -> DateTime time: {0:N3}, Timer time: {1:N3}", elapsedTime2, duration2); Assert.Between( duration2, elapsedTime1 * (1.0 - Variation), elapsedTime1 * (1.0 + Variation) ); }
public void StartStop() { HighResolutionTimer timer = new HighResolutionTimer(); timer.Start(); double elapsedTime = Wait(); timer.Stop(); double duration = timer.Duration(1) * TimeToMilliseconds; Console.WriteLine("DateTime time: {0:N3}, Timer time: {1:N3}", elapsedTime, duration); Assert.Between( duration, elapsedTime * (1.0 - Variation), elapsedTime * (1.0 + Variation) ); }