예제 #1
0
        private void EnsureStatisticsCalculated()
        {
            if (!statisticsCalculated)
            {
                _Best     = null;
                _Worst    = null;
                _NextBest = null;

                foreach (var item in Data)
                {
                    if (_Best == null || item.IterationsPerSecond > _Best.IterationsPerSecond)
                    {
                        _NextBest = _Best;
                        _Best     = item;
                    }
                    else if (_NextBest == null || item.IterationsPerSecond > _NextBest.IterationsPerSecond)
                    {
                        _NextBest = item;
                    }

                    if (_Worst == null || item.IterationsPerSecond < _Worst.IterationsPerSecond)
                    {
                        _Worst = item;
                    }
                }
            }
        }
예제 #2
0
        private double PctDiff(PerfData result1, PerfData result2, bool showPctWorse)
        {
            double faster = result1.IterationsPerSecond > result2.IterationsPerSecond ?
                            result1.IterationsPerSecond : result2.IterationsPerSecond;

            double slower = result1.IterationsPerSecond > result2.IterationsPerSecond ?
                            result2.IterationsPerSecond :result1.IterationsPerSecond;

            if (showPctWorse)
            {
                return(faster != 0 ?
                       Math.Round(slower / faster, 2) :
                       0);
            }
            else
            {
                return(slower != 0 ?
                       Math.Round(faster / slower, 2) :
                       0);
            }
        }
예제 #3
0
        private void EnsureStatisticsCalculated()
        {
            if (!statisticsCalculated)
            {
                _Best = null;
                _Worst = null;
                _NextBest = null;

                foreach (var item in Data)
                {
                    if (_Best == null || item.IterationsPerSecond > _Best.IterationsPerSecond)
                    {
                        _NextBest = _Best;
                        _Best = item;
                    }
                    else if (_NextBest == null || item.IterationsPerSecond > _NextBest.IterationsPerSecond)
                    {
                        _NextBest = item;
                    }

                    if (_Worst == null || item.IterationsPerSecond < _Worst.IterationsPerSecond)
                    {
                        _Worst = item;
                    }
                }
            }
        }
예제 #4
0
        public PerfData Test(Action action, TimeSpan maxTime, string testSource)
        {
            PerfData perfData = new PerfData {
                Source = testSource
            };
            double diffMs = 0;

            DateTime start = DateTime.Now;

            // first test 1 iteration to make sure it's not really slow
            try
            {
                action();
            }
            catch (Exception e)
            {
                perfData.Iterations   = 0;
                perfData.Time         = TimeSpan.FromSeconds(0);
                perfData.ErrorMessage = e.Message;
                return(perfData);
            }

            TimeSpan diff = DateTime.Now - start;

            if (diff > maxTime)
            {
                perfData.Iterations = 1;
                perfData.Time       = diff;
                return(perfData);
            }
            diffMs = diff.TotalMilliseconds;

            // now do a slightly better time estimate
            if (diffMs < maxTime.TotalMilliseconds / 100 || diffMs == 5)
            {
                start = DateTime.Now;
                int testIterations = 10;
                for (int i = 0; i < testIterations; i++)
                {
                    action();
                }
                diff   = DateTime.Now - start;
                diffMs = diff.TotalMilliseconds / testIterations;
            }

            int estimatedIterations = (int)Math.Floor(maxTime.TotalMilliseconds / diffMs);

            // Try to check the time only 10 times per second, e.g. if we expect 500 iterations
            // and time is 5 seconds than check every 10 iterations

            int blockSize = Math.Max(1, (int)Math.Floor(estimatedIterations / maxTime.TotalSeconds / 10));

            DateTime endTime = DateTime.Now + maxTime;

            int iterations = 0;

            start = DateTime.Now;

            while (DateTime.Now < endTime)
            {
                for (int i = 0; i < blockSize; i++)
                {
                    action();
                }
                iterations += blockSize;
            }

            TimeSpan totalTime = DateTime.Now - start;

            perfData.Iterations = iterations;
            perfData.Time       = totalTime;

            return(perfData);
        }
예제 #5
0
 private double HowMuchBetter(PerfData result1, PerfData result2)
 {
     return(PctDiff(result1, result2, false));
 }
예제 #6
0
 private double PercentWorse(PerfData result1, PerfData result2)
 {
     return((HowMuchWorse(result1, result2)) * 100);
 }
예제 #7
0
 private double HowMuchWorse(PerfData result1, PerfData result2)
 {
     return(PctDiff(result1, result2, true));
 }
예제 #8
0
        public PerfData Test(Action action, TimeSpan maxTime, string testSource) 
        {
            
            PerfData perfData = new PerfData { Source = testSource };
            double diffMs = 0;

            DateTime start = DateTime.Now;
            // first test 1 iteration to make sure it's not really slow
            try
            {
                action();
            }
            catch (Exception e)
            {
                perfData.Iterations = 0;
                perfData.Time = TimeSpan.FromSeconds(0);
                perfData.ErrorMessage = e.Message;
                return perfData;
            }

            TimeSpan diff = DateTime.Now - start;
            if (diff > maxTime) {
                perfData.Iterations=1;
                perfData.Time = diff;
                return perfData;
            }
            diffMs = diff.TotalMilliseconds;

            // now do a slightly better time estimate
            if (diffMs < maxTime.TotalMilliseconds/100 || diffMs == 5)
            {
                start = DateTime.Now;
                int testIterations = 10;
                for (int i = 0; i < testIterations; i++)
                {
                    action();
                }
                diff = DateTime.Now - start;
                diffMs = diff.TotalMilliseconds / testIterations;
            }

            int estimatedIterations = (int)Math.Floor(maxTime.TotalMilliseconds / diffMs);
            
            // Try to check the time only 10 times per second, e.g. if we expect 500 iterations 
            // and time is 5 seconds than check every 10 iterations

            int blockSize = Math.Max(1,(int)Math.Floor(estimatedIterations/maxTime.TotalSeconds/10));

            DateTime endTime = DateTime.Now + maxTime;

            int iterations=0;
            start = DateTime.Now;

            while (DateTime.Now < endTime) {
                for (int i=0;i<blockSize;i++) {
                    action();
                }
                iterations+=blockSize;
            }

            TimeSpan totalTime = DateTime.Now - start;

            perfData.Iterations = iterations;
            perfData.Time =totalTime;
 
            return perfData;
        }
예제 #9
0
        private double PctDiff(PerfData result1, PerfData result2, bool showPctWorse)
        {
            double faster = result1.IterationsPerSecond > result2.IterationsPerSecond ?
                result1.IterationsPerSecond : result2.IterationsPerSecond;

            double slower = result1.IterationsPerSecond > result2.IterationsPerSecond ?
                result2.IterationsPerSecond :result1.IterationsPerSecond;

            if (showPctWorse)
            {
                return faster != 0 ?
                    Math.Round(slower / faster, 2) :
                    0;
            }
            else
            {
                return slower != 0 ?
                Math.Round(faster / slower, 2) :
                0;
            }
        }
예제 #10
0
 private double HowMuchBetter(PerfData result1, PerfData result2)
 {
     return PctDiff(result1, result2, false);
 }
예제 #11
0
 private double HowMuchWorse(PerfData result1, PerfData result2)
 {
     return PctDiff(result1, result2, true);
 }
예제 #12
0
 private double PercentWorse(PerfData result1, PerfData result2)
 {
     return (HowMuchWorse(result1, result2)) * 100;
 }