コード例 #1
0
        private double[] GetMeasuresToAnalyze(BenchmarkedMethod method)
        {
            var measures     = method.Measures.Select(x => x.TotalMilliseconds).OrderBy(x => x);
            int measureCount = measures.Count();

            // CHECK: To cut best and worst results we need at least three samples, it's little
            // bit arbitrary but we may want to increase this threshold to a bigger population
            // because with a small number of samples this cut may be significative.
            if (!CutTails || measureCount <= 2)
            {
                return(measures.ToArray());
            }

            return(measures.Skip(1).Take(measureCount - 2).ToArray());
        }
コード例 #2
0
        public override Dictionary <string, object> Calculate(BenchmarkedMethod method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            var    measures = GetMeasuresToAnalyze(method);
            double total = 0, minimum = 0, maximum = 0;

            foreach (var measure in measures)
            {
                total += measure;

                if (minimum == 0) // Simple way, execution time may be small but it is always higher than zero
                {
                    minimum = measure;
                }
                else
                {
                    minimum = Math.Min(minimum, measure);
                }

                maximum = Math.Max(maximum, measure);
            }

            double average = measures.Length > 0 ? (total / measures.Length) : 0.0;

            return(new Dictionary <string, object>
            {
                { Properties.Resources.Minimum, TimeSpanFromMilliseconds(minimum) },
                { Properties.Resources.LowerQuartile, TimeSpanFromMilliseconds(Percentile(measures, 0.25)) },
                { Properties.Resources.Average, TimeSpanFromMilliseconds(average) },
                { Properties.Resources.UpperQuartile, TimeSpanFromMilliseconds(Percentile(measures, 0.75)) },
                { Properties.Resources.Maximum, TimeSpanFromMilliseconds(maximum) },
            });
        }
コード例 #3
0
        private static void WriteMeasuresForSingleTest(SpreadsheetLight.SLDocument document, int columnIndex, BenchmarkedMethod method)
        {
            Debug.Assert(document != null);
            Debug.Assert(columnIndex > 0);
            Debug.Assert(method != null);

            int rowIndex = 1;

            document.SetCellValue(rowIndex++, columnIndex, method.Name);

            foreach (var measure in method.Measures)
            {
                document.SetCellValue(rowIndex++, columnIndex, measure.TotalMilliseconds);
            }
        }
コード例 #4
0
 /// <summary>
 /// Calculate a set of values to describe benchmark results.
 /// </summary>
 /// <param name="method">Method which has been benchmarked.</param>
 /// <returns>
 /// Dictionary with values which decribes results of benchmark <paramref name="method"/>. Dictionary
 /// keys are given by <see cref="GetHeaders"/> and values can be both <see cref="Double"/> or <see cref="TimeSpan"/>.
 /// Unit of measure must always be <em>milliseconds</em>.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="method"/> is <see langword="null"/>.
 /// </exception>
 public abstract Dictionary <string, object> Calculate(BenchmarkedMethod method);