Beispiel #1
0
        public string GetValue(Summary summary, BenchmarkCase benchmark, ISummaryStyle style)
        {
            if (!summary.HasReport(benchmark))
            {
                return("-");
            }

            var results = summary[benchmark].ExecuteResults;

            if (results.Count != 1)
            {
                return("-");
            }

            var result = results.Single();
            var buffer = new StringBuilder();

            foreach (var line in result.ExtraOutput)
            {
                if (Metric.TryParse(line, out Metric metric))
                {
                    if (buffer.Length > 0)
                    {
                        buffer.Append(", ");
                    }

                    buffer.Append(metric.ToColumnValue());
                }
            }

            return(buffer.Length > 0 ? buffer.ToString() : "-");
        }
Beispiel #2
0
        private string Format(Summary summary, Statistics statistics, ISummaryStyle style)
        {
            if (statistics == null)
            {
                return("NA");
            }

            var allValues = summary
                            .Reports
                            .Where(r => r.ResultStatistics != null)
                            .Select(r => calc(r.ResultStatistics))
                            .Where(v => !double.IsNaN(v) && !double.IsInfinity(v))
                            .Select(v => type == UnitType.Time ? v / style.TimeUnit.NanosecondAmount : v)
                            .ToList();
            double minValue          = allValues.Any() ? allValues.Min() : 0;
            bool   allValuesAreZeros = allValues.All(v => Math.Abs(v) < 1e-9);
            string format            = "N" + (allValuesAreZeros ? 1 : GetBestAmountOfDecimalDigits(minValue));

            double value = calc(statistics);

            if (double.IsNaN(value))
            {
                return("NA");
            }
            return(type == UnitType.Time
                   ? value.ToTimeStr(style.TimeUnit, summary.Config.Encoding, format, 1, style.PrintUnitsInContent)
                   : value.ToStr(format));
        }
Beispiel #3
0
        string Format(Summary summary, Benchmark benchmark, ISummaryStyle style)
        {
            Statistics statistics = summary[benchmark].ResultStatistics;
            var        items      = (int)benchmark.Parameters["Items"];


            if (statistics == null)
            {
                return("NA");
            }

            var allValues = summary
                            .Reports
                            .Where(r => r.ResultStatistics != null)
                            .Select(r => _calc(items, r.ResultStatistics))
                            .Where(v => !double.IsNaN(v) && !double.IsInfinity(v))
                            .Select(v => UnitType == UnitType.Time ? v / 1 : v)
                            .ToList();
            double minValue          = allValues.Any() ? allValues.Min() : 0;
            bool   allValuesAreZeros = allValues.All(v => Math.Abs(v) < 1e-9);
            string format            = "N" + (allValuesAreZeros ? 1 : GetBestAmountOfDecimalDigits(minValue));

            double value = _calc(items, statistics);

            if (double.IsNaN(value))
            {
                return("NA");
            }
            return(UnitType == UnitType.Time ? value.ToTimeStr(style.TimeUnit, 1, style.PrintUnitsInContent, format: format) : value.ToString(format));
        }
Beispiel #4
0
        internal SummaryTable(Summary summary, ISummaryStyle style = null)
        {
            Summary = summary;

            if (summary.HasCriticalValidationErrors)
            {
                Columns                 = Array.Empty <SummaryTableColumn>();
                ColumnCount             = 0;
                FullHeader              = Array.Empty <string>();
                FullContent             = Array.Empty <string[]>();
                FullContentStartOfGroup = Array.Empty <bool>();
                FullContentWithHeader   = Array.Empty <string[]>();
                IsDefault               = Array.Empty <bool>();
                return;
            }

            // Ensure we have all required data for styling
            style = style ?? SummaryStyle.Default;
            if (style.TimeUnit == null)
            {
                style = style.WithTimeUnit(TimeUnit.GetBestTimeUnit(summary.Reports.Where(r => r.ResultStatistics != null).Select(r => r.ResultStatistics.Mean).ToArray()));
            }
            if (style.SizeUnit == null)
            {
                style = style.WithSizeUnit(SizeUnit.GetBestSizeUnit(summary.Reports.Select(r => r.GcStats.BytesAllocatedPerOperation).ToArray()));
            }

            var columns = summary.GetColumns();

            ColumnCount = columns.Length;
            FullHeader  = columns.Select(c => c.GetColumnTitle(style)).ToArray();

            var orderProvider = summary.Config.GetOrderProvider() ?? DefaultOrderProvider.Instance;

            FullContent = summary.Reports.Select(r => columns.Select(c => c.GetValue(summary, r.Benchmark, style)).ToArray()).ToArray();
            IsDefault   = columns.Select(c => summary.Reports.All(r => c.IsDefault(summary, r.Benchmark))).ToArray();
            var groupKeys = summary.Benchmarks.Select(b => orderProvider.GetGroupKey(b, summary)).ToArray();

            FullContentStartOfGroup = new bool[summary.Reports.Length];

            if (groupKeys.Distinct().Count() > 1 && FullContentStartOfGroup.Length > 0)
            {
                FullContentStartOfGroup[0] = true;
                for (int i = 1; i < summary.Reports.Length; i++)
                {
                    FullContentStartOfGroup[i] = groupKeys[i] != groupKeys[i - 1];
                }
            }

            var full = new List <string[]> {
                FullHeader
            };

            full.AddRange(FullContent);
            FullContentWithHeader = full.ToArray();

            Columns = Enumerable.Range(0, columns.Length).Select(i => new SummaryTableColumn(this, i, columns[i])).ToArray();
            EffectiveSummaryStyle = style;
        }
Beispiel #5
0
    public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style)
    {
        var hash = ((byte[])benchmark.Target.Method.Invoke(null, null)).ToHexString();

        if (hash.Length > 16)
        {
            hash = hash.Substring(0, 12) + "...";
        }
        return(hash);
    }
            public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style)
            {
                if (!results.ContainsKey(benchmark) || results[benchmark] == null)
                {
                    return("N/A");
                }

                var value = results[benchmark].AllocatedBytes / (double)results[benchmark].TotalOperations;

                return(UnitType == UnitType.Size ? ((long)value).ToSizeStr(style.SizeUnit, 1, style.PrintUnitsInContent) : value.ToStr());
            }
            public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style)
            {
                if (!results.ContainsKey(benchmark) || benchmark.Job.Env.Runtime is MonoRuntime)
                {
                    return("N/A");
                }

                var value = results[benchmark].BytesAllocatedPerOperation;

                return(UnitType == UnitType.Size ? value.ToSizeStr(style.SizeUnit, 1, style.PrintUnitsInContent) : ((double)value).ToStr());
            }
Beispiel #8
0
        /// <summary>Returns value for the column.</summary>
        /// <param name="summary">Summary for the run.</param>
        /// <param name="benchmark">The benchmark.</param>
        /// <param name="style">The summary style.</param>
        /// <returns>The value for the column</returns>
        public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style)
        {
            double result;
            var    metric = Metric;

            if (metric.IsRelative && benchmark.Target.Baseline)
            {
                switch (_kind)
                {
                case Kind.Min:
                case Kind.Mean:
                case Kind.Max:
                    result = 1.0;
                    break;

                case Kind.StdDev:
                    result = 0.0;
                    break;

                default:
                    result = double.NaN;
                    break;
                }
            }
            else
            {
                var valuesProvider = metric.ValuesProvider;
                switch (_kind)
                {
                case Kind.Min:
                    result = valuesProvider.TryGetLimitValues(benchmark, summary).Min;
                    break;

                case Kind.Mean:
                    result = valuesProvider.TryGetMeanValue(benchmark, summary) ?? double.NaN;
                    break;

                case Kind.Max:
                    result = valuesProvider.TryGetLimitValues(benchmark, summary).Max;
                    break;

                case Kind.StdDev:
                    result = valuesProvider.TryGetVariance(benchmark, summary) ?? double.NaN;
                    break;

                default:
                    result = double.NaN;
                    break;
                }
            }

            return(double.IsNaN(result) ? "?" : result.ToString(metric.MetricUnits));
        }
Beispiel #9
0
        private string Format(Statistics statistics, ISummaryStyle style)
        {
            if (statistics == null)
            {
                return("NA");
            }
            double value = calc(statistics);

            if (double.IsNaN(value))
            {
                return("NA");
            }
            return(type == UnitType.Time ? value.ToTimeStr(style.TimeUnit, 1, style.PrintUnitsInContent) : value.ToStr());
        }
Beispiel #10
0
 public void Add(IConfig config)
 {
     columnProviders.AddRange(config.GetColumnProviders());
     exporters.AddRange(config.GetExporters());
     loggers.AddRange(config.GetLoggers());
     diagnosers.AddRange(config.GetDiagnosers());
     analysers.AddRange(config.GetAnalysers());
     jobs.AddRange(config.GetJobs());
     validators.AddRange(config.GetValidators());
     hardwareCounters.AddRange(config.GetHardwareCounters());
     orderProvider       = config.GetOrderProvider() ?? orderProvider;
     KeepBenchmarkFiles |= config.KeepBenchmarkFiles;
     summaryStyle        = summaryStyle ?? config.GetSummaryStyle();
 }
            public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style)
            {
                System.Reflection.MethodInfo mi = benchmarkCase.Descriptor.WorkloadMethod;
                if (mi.Name.Contains("Serialize"))
                {
                    var instance = Activator.CreateInstance(mi.DeclaringType);
                    mi.DeclaringType.GetField("Serializer").SetValue(instance, benchmarkCase.Parameters[0].Value);

                    var bytes = (byte[])mi.Invoke(instance, null);
                    return(ToHumanReadableSize(bytes.Length));
                }
                else
                {
                    return("-");
                }
            }
Beispiel #12
0
 public void Add(IConfig config)
 {
     columnProviders.AddRange(config.GetColumnProviders());
     exporters.AddRange(config.GetExporters());
     loggers.AddRange(config.GetLoggers());
     diagnosers.AddRange(config.GetDiagnosers());
     analysers.AddRange(config.GetAnalysers());
     AddJobs(config.GetJobs());
     validators.AddRange(config.GetValidators());
     hardwareCounters.AddRange(config.GetHardwareCounters());
     filters.AddRange(config.GetFilters());
     orderer             = config.GetOrderer() ?? orderer;
     KeepBenchmarkFiles |= config.KeepBenchmarkFiles;
     ArtifactsPath       = config.ArtifactsPath ?? ArtifactsPath;
     Encoding            = config.Encoding ?? Encoding;
     summaryStyle        = summaryStyle ?? config.GetSummaryStyle();
     logicalGroupRules.AddRange(config.GetLogicalGroupRules());
 }
Beispiel #13
0
        /// <summary>
        /// Gets column title formatted using the specified style
        /// </summary>
        public static string GetColumnTitle(this IColumn column, ISummaryStyle style)
        {
            if (!style.PrintUnitsInHeader)
            {
                return(column.ColumnName);
            }

            switch (column.UnitType)
            {
            case UnitType.Size:
                return($"{column.ColumnName} [{style.SizeUnit.Name}]");

            case UnitType.Time:
                return($"{column.ColumnName} [{style.TimeUnit.Name}]");

            default:
                return(column.ColumnName);
            }
        }
        public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style)
        {
            string result = "No non-null array arguments";

            if (benchmarkCase.HasArguments || benchmarkCase.HasParameters)
            {
                result = "";

                for (int i = 0; i < benchmarkCase.Parameters.Count; ++i)
                {
                    bool addSpace = false;

                    if (benchmarkCase.Parameters[i].Value is IList)
                    {
                        result += ((addSpace) ? " " : "")
                                  + (style.SizeUnit.Name == "Print name" ? benchmarkCase.Parameters[i].Name : "")
                                  + ((IList)(benchmarkCase.Parameters[i].Value)).Count;
                        addSpace = true;
                    }
                }
            }

            return(result);
        }
Beispiel #15
0
 public void Set(ISummaryStyle style) => summaryStyle = style ?? summaryStyle;
 public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style) => benchmark.Target.Method.ReturnType.Name;
Beispiel #17
0
 /// <summary>Sets the specified summary style.</summary>
 /// <param name="summaryStyle">The summary style.</param>
 public void Set(ISummaryStyle summaryStyle) => SummaryStyle = summaryStyle ?? SummaryStyle;
 public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style) => GetValue(summary, benchmark);
 public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style)
 {
     return(_parent.GetValue(summary, benchmark, style));
 }
 public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style) => benchmark.Target.Method.DeclaringType.Name.Replace("Benchmarks", string.Empty);
Beispiel #21
0
 public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style) => GetValue(summary, benchmarkCase);
Beispiel #22
0
 public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style)
 => Results.TryGetValue(benchmarkCase, out var stats) && stats.Counters.ContainsKey(HardwareCounter.InstructionRetired) && stats.Counters.ContainsKey(HardwareCounter.TotalCycles)
         ? (stats.Counters[HardwareCounter.InstructionRetired].Count / (double)stats.Counters[HardwareCounter.TotalCycles].Count).ToString("N2")
         : "-";
Beispiel #23
0
 [PublicAPI] public static IConfig With(this IConfig config, ISummaryStyle summaryStyle) => config.With(c => c.Set(summaryStyle));
Beispiel #24
0
 public string GetValue(Summary summary, Benchmark benchmark, ISummaryStyle style)
 => Format(summary, summary[benchmark].ResultStatistics, style);
Beispiel #25
0
 public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style)
 => Results.TryGetValue(benchmarkCase, out var stats) && stats.Counters.ContainsKey(HardwareCounter.BranchMispredictions) && stats.Counters.ContainsKey(HardwareCounter.BranchInstructions)
         ? (stats.Counters[HardwareCounter.BranchMispredictions].Count / (double)stats.Counters[HardwareCounter.BranchInstructions].Count).ToString(style.PrintUnitsInContent ? "P2" : String.Empty)
         : "-";
Beispiel #26
0
 internal SummaryTable GetTable(ISummaryStyle style) => new SummaryTable(this, style);
Beispiel #27
0
 public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style)
 {
     return(GetValue(summary, benchmarkCase));
 }
Beispiel #28
0
        public string GetValue(Summary summary, BenchmarkCase benchmark, ISummaryStyle style)
        {
            var property = typeof(ClassificationMetrics).GetProperty(_metricName);

            return(property.GetValue(StochasticDualCoordinateAscentClassifierBench.s_metrics).ToString());
        }
Beispiel #29
0
 public CsvMeasurementsExporter(CsvSeparator separator, ISummaryStyle style = null)
 {
     this.separator = separator;
     Style          = style ?? SummaryStyle.Default;
 }
 public CsvExporter(CsvSeparator separator, ISummaryStyle style)
 {
     this.style     = style;
     this.separator = separator;
 }