コード例 #1
0
        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)
                );
        }
コード例 #2
0
        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));
        }