Beispiel #1
0
        public PerfIteratorResult Run(Action targetAction)
        {
            for (int i = 0; i < WarmupCount; ++i)
            {
                targetAction();
            }

            var stopWatch = new Stopwatch();
            var resultsList = new List<PerfRoundResult>();
            for (int i = 0; i < RepeatCount; ++i)
            {
                ulong totalTicks = 0;
                var maxTicks = ulong.MinValue;
                var minTicks = ulong.MaxValue;

                for (int j = 0; j < IterationCount; ++j)
                {
                    stopWatch.Start();
                    targetAction();
                    stopWatch.Stop();
                    var ticks = (ulong)stopWatch.ElapsedTicks;
                    totalTicks += ticks;
                    maxTicks = Math.Max(ticks, maxTicks);
                    minTicks = Math.Min(ticks, minTicks);
                    stopWatch.Reset();
                }
                var runResult = new PerfRoundResult(totalTicks, maxTicks, minTicks, IterationCount);
                resultsList.Add(runResult);
            }

            var result = new PerfIteratorResult(resultsList);
            return result;
        }
Beispiel #2
0
        public PerfIteratorResult Run(Action targetAction)
        {
            for (int i = 0; i < this.WarmupCount; ++i)
            {
                targetAction();
            }

            var stopWatch   = new Stopwatch();
            var resultsList = new List <PerfRoundResult>();

            for (int i = 0; i < this.RepeatCount; ++i)
            {
                ulong totalTicks = 0;
                var   maxTicks   = ulong.MinValue;
                var   minTicks   = ulong.MaxValue;

                for (int j = 0; j < this.IterationCount; ++j)
                {
                    stopWatch.Start();
                    targetAction();
                    stopWatch.Stop();
                    var ticks = (ulong)stopWatch.ElapsedTicks;
                    totalTicks += ticks;
                    maxTicks    = Math.Max(ticks, maxTicks);
                    minTicks    = Math.Min(ticks, minTicks);
                    stopWatch.Reset();
                }

                var runResult = new PerfRoundResult(totalTicks, maxTicks, minTicks, this.IterationCount);
                resultsList.Add(runResult);
            }

            var result = new PerfIteratorResult(resultsList);

            return(result);
        }