public static BenchmarkResult[] StartMultiple(Action[] actionsToProfile, BenchmarkParameters parameters)
        {
            var results = new BenchmarkResult[actionsToProfile.Length];

            for (var i = 0; i < actionsToProfile.Length; i++)
            {
                results[i] = Start(actionsToProfile[i], parameters);
            }

            return(results);
        }
        private Benchmarker(BenchmarkResult result)
        {
            _timer  = Stopwatch.StartNew();
            _result = result;

            // Collect current collections counts, in order to calculate
            // them correctly later.
            _initialCollection0Count = GC.CollectionCount(0);
            _initialCollection1Count = GC.CollectionCount(1);
            _initialCollection2Count = GC.CollectionCount(2);
        }
        public static BenchmarkComparison[] Compare(BenchmarkResult baseline, params BenchmarkResult[] comparing)
        {
            var comparisons = new BenchmarkComparison[comparing.Length];

            for (int i = 0; i < comparing.Length; i++)
            {
                var comparison = new BenchmarkComparison();
                comparison.Compare(baseline, comparing[i]);
                comparisons[i] = comparison;
            }

            return(comparisons);
        }
        internal void Compare(BenchmarkResult from, BenchmarkResult to)
        {
            CompareFrom = from;
            CompareTo   = to;

            ElapsedMillisecondsDifference = to.ElapsedMilliseconds - from.ElapsedMilliseconds;
            if (from.ElapsedMilliseconds > 0)
            {
                ElapsedMillisecondsDifferencePercentage = (ElapsedMillisecondsDifference / from.ElapsedMilliseconds) * 100;
            }

            ElapsedTicksDifference = to.ElapsedTicks - from.ElapsedTicks;
            if (from.ElapsedTicks > 0)
            {
                ElapsedTicksDifferencePercentage = (ElapsedTicksDifference / from.ElapsedTicks) * 100;
            }

            AverageMillisecondsDifference = to.AverageMilliseconds - from.AverageMilliseconds;
            if (from.AverageMilliseconds > 0)
            {
                AverageMillisecondsDifferencePercentage = (AverageMillisecondsDifference / from.AverageMilliseconds) * 100;
            }

            AverageTicksDifference           = to.AverageTicks - from.AverageTicks;
            AverageTicksDifferencePercentage = (AverageTicksDifference / from.AverageTicks) * 100;

            GCCollections0Difference = to.GarbageCollections0Count - from.GarbageCollections0Count;
            if (from.GarbageCollections0Count > 0)
            {
                GCCollections0DifferencePercentage = (GCCollections0Difference / from.GarbageCollections0Count) * 100;
            }

            GCCollections1Difference = to.GarbageCollections1Count - from.GarbageCollections1Count;
            if (from.GarbageCollections1Count > 0)
            {
                GCCollections1DifferencePercentage = (GCCollections1Difference / from.GarbageCollections1Count) * 100;
            }

            GCCollections2Difference = to.GarbageCollections2Count - from.GarbageCollections2Count;
            if (from.GarbageCollections2Count > 0)
            {
                GCCollections2DifferencePercentage = (GCCollections2Difference / from.GarbageCollections2Count) * 100;
            }
        }
 public static Benchmarker StartScope(BenchmarkResult result)
 {
     return(new Benchmarker(result));
 }