Beispiel #1
0
        /// <summary>
        /// Returns a <see cref="DataSize"/> that is the highest value which will have a non-zero whole-number <see cref="Size"/> component.
        /// </summary>
        /// <param name="unit">When set to <see cref="SizeUnit.Bytes"/> the result will be a <code>B</code> type, when set to <see cref="SizeUnit.Bits"/> the result will be a <code>iB</code> type. If set to <code>null</code> the same base unit as the source value will be used.</param>
        /// <returns>A <see cref="DataSize"/> object.</returns>
        public DataSize GetLargestWholeSize(SizeUnit? unit = null)
        {
            var limit = 1000ul;

            if (unit == null)
            {
                unit = (SizeUnit)((int)Unit & 0x00FF);
            }

            if (unit == SizeUnit.Bits)
            {
                limit = 1024ul;
            }

            var iterations = 0;
            var currSize = (double)SizeInBytes;

            while (currSize >= limit)
            {
                currSize /= limit;
                iterations++;
            }

            return new DataSize(currSize, (SizeUnit)((iterations << 8) | ((int)unit & 0x00FF)));
        }
 public FileSizeFilterSettings(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     minimalSize__ = info.GetInt32("MinimalSize");
     maximalSize__ = info.GetInt32("MaximalSize");
     unit__ = (SizeUnit)info.GetInt32("SizeUnit");
 }
Beispiel #3
0
        public double GetSize(SizeUnit unit)
        {
            if (unit == SizeUnit.Bits)
            {
                return SizeInBytes * 8.0;
            }

            if (((int)unit & 0x03) == (int)SizeUnit.Bytes)
            {
                return SizeInBytes / Math.Pow(10, 3 * (((int)unit & 0xFF00) >> 8));
            }

            return SizeInBytes / Math.Pow(2, 10 * (((int)unit & 0xFF00) >> 8));
        }
Beispiel #4
0
        private DataSize(double size, SizeUnit unit)
        {
            Unit = unit;

            if (unit == SizeUnit.Bits)
            {
                SizeInBytes = (uint)(size / 8);
                return;
            }

            if (((int)unit & 0x03) == (int)SizeUnit.Bytes)
            {
                SizeInBytes = (uint)(size * Math.Pow(10, 3 * (((int)unit & 0xFF00) >> 8)));
                return;
            }

            SizeInBytes = (uint)(size * Math.Pow(2, 10 * (((int)unit & 0xFF00) >> 8)));
        }
Beispiel #5
0
        public void SizeUnit_should_have_equality_operators()
        {
            Assert.True(SizeUnit.Unlimited == SizeUnit.Unlimited);
            Assert.True(SizeUnit.NotSet == SizeUnit.NotSet);
            Assert.True(SizeUnit.Absolute(10) == SizeUnit.Absolute(10));

            Assert.False(SizeUnit.Unlimited == SizeUnit.NotSet);
            Assert.False(SizeUnit.NotSet == SizeUnit.Absolute(10));
            Assert.False(SizeUnit.Absolute(10) == SizeUnit.Unlimited);
            Assert.False(SizeUnit.Absolute(10) == SizeUnit.Absolute(11));

            Assert.False(SizeUnit.Unlimited != SizeUnit.Unlimited);
            Assert.False(SizeUnit.NotSet != SizeUnit.NotSet);
            Assert.False(SizeUnit.Absolute(10) != SizeUnit.Absolute(10));

            Assert.True(SizeUnit.Unlimited != SizeUnit.NotSet);
            Assert.True(SizeUnit.NotSet != SizeUnit.Absolute(10));
            Assert.True(SizeUnit.Absolute(10) != SizeUnit.Unlimited);
            Assert.True(SizeUnit.Absolute(10) != SizeUnit.Absolute(11));
        }
Beispiel #6
0
        /// <summary>
        /// Gets the size of the byte.
        /// </summary>
        /// <param name="size">The size.</param>
        /// <param name="unit">The unit.</param>
        /// <returns></returns>
        public static long GetByteSize(int size, SizeUnit unit)
        {
            switch (unit)
            {
            case SizeUnit.Gb:
                return(size * SizeGb);

            case SizeUnit.Mb:
                return(size * SizeMb);

            case SizeUnit.Kb:
                return(size * SizeKb);

            case SizeUnit.b:
                return(size);

            default:
                return(size);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets the unit count.
        /// </summary>
        /// <param name="byteSize">Size of the byte.</param>
        /// <param name="unit">The unit.</param>
        /// <returns></returns>
        public static long GetUnitCount(long byteSize, SizeUnit unit)
        {
            switch (unit)
            {
            case SizeUnit.Gb:
                return(byteSize / SizeGb);

            case SizeUnit.Mb:
                return(byteSize / SizeMb);

            case SizeUnit.Kb:
                return(byteSize / SizeKb);

            case SizeUnit.b:
                return(byteSize);

            default:
                return(byteSize);
            }
        }
Beispiel #8
0
        GetCurrentDiskSpaceTotalAndUsedPercentAllDrives(SizeUnit sizeUnit = SizeUnit.Bytes)
        {
            DriveInfo[] allDrives = DriveInfo.GetDrives();

            var tuples = new List <(string, double, int)>();

            for (int i = 0; i < allDrives.Length; i++)
            {
                if (!allDrives[i].IsReady)
                {
                    continue;
                }

                var drivename = allDrives[i].Name;
                var totalSize = GetTotalDiskSpace(drivename, sizeUnit);
                var pctUsed   = GetCurrentDiskSpaceUsedPercent(drivename);
                tuples.Add((drivename.Substring(0, 1), totalSize, pctUsed));
            }

            return(tuples);
        }
Beispiel #9
0
        public static string Abbreviation(this SizeUnit unit)
        {
            if (unit == SizeUnit.Bytes)
            {
                return("B");
            }

            if (unit == SizeUnit.Bits)
            {
                return("b");
            }

            var firstLetter = unit.ToString()[0] + "";

            if (((int)unit & 0x00FF) == (int)SizeUnit.Bits)
            {
                return(firstLetter + "iB");
            }

            return(firstLetter + "B");
        }
Beispiel #10
0
        internal static double GetInchValue(SizeUnit unit, double dpi, double value)
        {
            double result = 0;

            switch (unit)
            {
            case SizeUnit.Pixels:
            default:
                result = value / dpi;
                break;

            case SizeUnit.Inches:
                result = value;
                break;

            case SizeUnit.Cm:
                result = value / dpi;
                break;
            }
            return(result);
        }
Beispiel #11
0
        public void Measure_should_use_Width_and_Height_if_provided(string width, string height, int expectedWidth, int expectedHeight, int desiredWidth, int desiredHeight)
        {
            var inputSize         = new Size(15, 20);
            var fixedMeasureSize  = new Size(20, 30);
            var receivedInputSize = Size.Empty;

            var component = new TestableComponent
            {
                Width             = SizeUnit.Parse(width),
                Height            = SizeUnit.Parse(height),
                OnMeasureCallback = x =>
                {
                    receivedInputSize = x;
                    return(fixedMeasureSize);
                }
            };

            component.Measure(inputSize, TestRendererContext.Instance);

            component.DesiredSize.ShouldBe(new Size(desiredWidth, desiredHeight));
            receivedInputSize.ShouldBe(new Size(expectedWidth, expectedHeight));
        }
Beispiel #12
0
        public static ulong AsBytes(SizeUnit unit, uint size)
        {
            switch (unit)
            {
            case SizeUnit.B:
                return(size);

            case SizeUnit.KB:
                return(OneKb * size);

            case SizeUnit.MB:
                return(size * OneMb);

            case SizeUnit.GB:
                return(size * OneGb);

            case SizeUnit.TB:
                return(size * OneTb);
            }

            return(0);
        }
Beispiel #13
0
        private static long ConvertToBytes(long value, SizeUnit unit)
        {
            switch (unit)
            {
            case SizeUnit.Bytes:
                return(value);

            case SizeUnit.Kilobytes:
                return(value * OneKb);

            case SizeUnit.Megabytes:
                return(value * OneMb);

            case SizeUnit.Gigabytes:
                return(value * OneGb);

            case SizeUnit.Terabytes:
                return(value * OneTb);

            default:
                throw new NotSupportedException("Not supported size unit: " + unit);
            }
        }
Beispiel #14
0
 internal static double Convert(double size, SizeUnit currentUnit, SizeUnit TargetUnit)
 {
     if (currentUnit == TargetUnit)
     {
         return(size);                                       //Em-Em, Pt-Pt, Px-Px
     }
     else if (currentUnit == SizeUnit.EMS)
     {
         return(ConvertFromEms((int)size, TargetUnit));                                              //Em-Pt, Em-Px
     }
     else if (TargetUnit == SizeUnit.EMS)
     {
         return(ConvertToEms(size, currentUnit));                                             //Pt-Em, Px-Em
     }
     else if (TargetUnit == SizeUnit.PIXELS)
     {
         return(size / 72.0 * 96);                                                //Pt-Px
     }
     else
     {
         return(size * 96.0 / 72);            //Px-Pt
     }
 }
        private static double ConvertToSizeUnits(double amount, SizeUnit sizeUnit)
        {
            switch (sizeUnit)
            {
            case SizeUnit.Bytes:
                return(amount);

            case SizeUnit.Kilobytes:
                return(amount / 1024);

            case SizeUnit.Megabytes:
                return(amount / 1024 / 1024);

            case SizeUnit.Gigabytes:
                return(amount / 1024 / 1024 / 1024);

            case SizeUnit.Terabytes:
                return(amount / 1024 / 1024 / 1024 / 1024);

            default:
                return(amount);
            }
        }
 public SizeInfo(long bytesSize)
 {
     if (bytesSize >= GbSize)
     {
         Size = Math.Round(bytesSize / GbSizeDivisor, 2);
         Unit = SizeUnit.GBYTE;
     }
     else if (bytesSize >= MbSize)
     {
         Size = Math.Round(bytesSize / MbSizeDivisor, 1);
         Unit = SizeUnit.MBYTE;
     }
     else if (bytesSize >= KbSize)
     {
         Size = Math.Round(bytesSize / KbSizeDivisor, 0);
         Unit = SizeUnit.KBYTE;
     }
     else
     {
         Size = bytesSize;
         Unit = SizeUnit.BYTE;
     }
 }
Beispiel #17
0
        public long GetValue(SizeUnit requestedUnit)
        {
            switch (requestedUnit)
            {
            case SizeUnit.Bytes:
                return(valueInBytes);

            case SizeUnit.Kilobytes:
                return(valueInBytes / OneKb);

            case SizeUnit.Megabytes:
                return(valueInBytes / OneMb);

            case SizeUnit.Gigabytes:
                return(valueInBytes / OneGb);

            case SizeUnit.Terabytes:
                return(valueInBytes / OneTb);

            default:
                throw new NotSupportedException("Not supported size unit: " + unit);
            }
        }
Beispiel #18
0
        public long GetValue(SizeUnit requestedUnit)
        {
            switch (requestedUnit)
            {
            case SizeUnit.Bytes:
                return(_valueInBytes);

            case SizeUnit.Kilobytes:
                return(_valueInBytes / OneKb);

            case SizeUnit.Megabytes:
                return(_valueInBytes / OneMb);

            case SizeUnit.Gigabytes:
                return(_valueInBytes / OneGb);

            case SizeUnit.Terabytes:
                return(_valueInBytes / OneTb);

            default:
                ThrowUnsupportedSize();
                return(-1);   // never hit
            }
        }
Beispiel #19
0
 private void UnitSwitch_Click(object sender, EventArgs e)
 {
     var names = Enum.GetNames(typeof(SizeUnit)).ToList();
     int i = names.Select(s => s.ToLower()).ToList().IndexOf(UnitSwitch.Text.ToLower());
     SizeUnit = i < names.Count - 1 ?
         (SizeUnit)Enum.Parse(typeof(SizeUnit), names[i + 1]) :
         (SizeUnit)Enum.Parse(typeof(SizeUnit), names[0]); // go back to first
     SizeLength = sizeLength; // trigger set logic
 }
Beispiel #20
0
 public static double GetTotalDiskSpace(string driveName, SizeUnit sizeUnit = SizeUnit.Bytes)
 {
     return(GetTotalDiskSpace(new DriveInfo(driveName), sizeUnit));
 }
Beispiel #21
0
 public DataSize(ulong sizeInBytes, SizeUnit unit)
 {
     Unit = unit;
     SizeInBytes = sizeInBytes;
 }
Beispiel #22
0
 public static DataSize From(double size, SizeUnit unit) => new DataSize(size, unit);
Beispiel #23
0
        internal SummaryTable(Summary summary, SummaryStyle style = null)
        {
            Summary = summary;

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

            // Ensure we have all required data for styling
            style = style ?? summary.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.GetBytesAllocatedPerOperation(r.BenchmarkCase)).ToArray()));
            }

            var columns = summary.GetColumns();

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

            FullContent = summary.Reports.Select(r => columns.Select(c => c.GetValue(summary, r.BenchmarkCase, style)).ToArray()).ToArray();
            IsDefault   = columns.Select(c => summary.Reports.All(r => c.IsDefault(summary, r.BenchmarkCase))).ToArray();

            var highlightGroupKeys = summary.BenchmarksCases.Select(b => b.Config.Orderer.GetHighlightGroupKey(b)).ToArray();

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

            var logicalGroupKeys = summary.BenchmarksCases
                                   .Select(b => b.Config.Orderer.GetLogicalGroupKey(summary.BenchmarksCases, b))
                                   .ToArray();

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

            SeparateLogicalGroups = summary.Orderer.SeparateLogicalGroups;

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

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

            Columns = new SummaryTableColumn[columns.Length];
            for (int i = 0; i < columns.Length; i++)
            {
                var  column = columns[i];
                bool hide   = summary.ColumnHidingRules.Any(rule => rule.NeedToHide(column));
                Columns[i] = new SummaryTableColumn(this, i, column, hide);
            }

            EffectiveSummaryStyle = style;
        }
Beispiel #24
0
 static string GetMarkerSize(double value, SizeUnit sizeUnit)
 {
     //Halve the resulting size to get approximate same size as it would look under basic stylization
     return((SizeInMM(value, sizeUnit) / 2.0).ToString(CultureInfo.InvariantCulture));
 }
Beispiel #25
0
 public string ToString(SizeUnit unit) => $"{GetSize(unit)} {unit.Abbreviation()}";
Beispiel #26
0
            public string ToString(SizeUnit sizeUnit)
            {
                var unitValue = SizeUnit.Convert(Bytes, SizeUnit.B, sizeUnit);

                return(unitValue.ToString("0.##", CultureInfo.InvariantCulture));
            }
Beispiel #27
0
 public SizeValue(long bytes, SizeUnit unit) : this(bytes * unit.ByteAmount)
 {
 }
        private string Write95_SizeUnit(SizeUnit v)
        {
            switch (v)
            {
                case SizeUnit.Byte:
                    return "Byte";

                case SizeUnit.KiloByte:
                    return "KiloByte";

                case SizeUnit.MegaByte:
                    return "MegaByte";
            }
            long num = (long) v;
            throw base.CreateInvalidEnumValueException(num.ToString(CultureInfo.InvariantCulture), "Nomad.Commons.SizeUnit");
        }
        public SummaryStyle([CanBeNull] CultureInfo cultureInfo, bool printUnitsInHeader, SizeUnit sizeUnit, TimeUnit timeUnit, bool printUnitsInContent = true,
                            bool printZeroValuesInContent = false, int maxParameterColumnWidth = DefaultMaxParameterColumnWidth, RatioStyle ratioStyle = RatioStyle.Value)
        {
            if (maxParameterColumnWidth < DefaultMaxParameterColumnWidth)
            {
                throw new ArgumentOutOfRangeException(nameof(maxParameterColumnWidth), $"{DefaultMaxParameterColumnWidth} is the minimum.");
            }

            CultureInfo              = cultureInfo ?? DefaultCultureInfo.Instance;
            PrintUnitsInHeader       = printUnitsInHeader;
            PrintUnitsInContent      = printUnitsInContent;
            SizeUnit                 = sizeUnit;
            TimeUnit                 = timeUnit;
            PrintZeroValuesInContent = printZeroValuesInContent;
            MaxParameterColumnWidth  = maxParameterColumnWidth;
            RatioStyle               = ratioStyle;
        }
Beispiel #30
0
        public static double GetTotalDiskSpace(DriveInfo driveInfo, SizeUnit sizeUnit = SizeUnit.Bytes)
        {
            long total = driveInfo.TotalSize;

            return(Math.Round(ConvertToSizeUnits(total, sizeUnit), 2));
        }
Beispiel #31
0
 public string ToString(string numberFormat, SizeUnit unit) => $"{GetSize(unit).ToString(numberFormat)} {unit.Abbreviation()}";
Beispiel #32
0
 static string GetLineThickness(double value, SizeUnit unit)
 {
     return(SizeInMM(value, unit).ToString(CultureInfo.InvariantCulture));
 }
Beispiel #33
0
 public DataSize(ulong sizeInBytes)
 {
     Unit = SizeUnit.Bytes;
     SizeInBytes = sizeInBytes;
 }
Beispiel #34
0
 public SizeUnitAttribute(SizeUnit unit)
 {
     Unit = unit;
 }
Beispiel #35
0
        public void ParseArguments_Should_Handle_Unit_Argument(string argument, string value, SizeUnit expected, string message)
        {
            // ACT
            var parameters = Helper.ParseArguments("fileName", $"{argument}={value}");

            // ASSERT
            parameters.FileSizeUnit.Should().Be(expected, message);
        }
 public SummaryStyle WithSizeUnit(SizeUnit sizeUnit)
 => new SummaryStyle(PrintUnitsInHeader, sizeUnit, TimeUnit, PrintUnitsInContent);
 public ApproximateSize(float value, SizeUnit unit)
 {
     Value = value;
     Unit  = unit;
 }
 public SummaryStyle WithSizeUnit(SizeUnit sizeUnit)
 => new SummaryStyle(CultureInfo, PrintUnitsInHeader, sizeUnit, TimeUnit, PrintUnitsInContent, PrintZeroValuesInContent, MaxParameterColumnWidth, RatioStyle);
Beispiel #39
0
        private static void DisplayDiff(IEnumerable <Benchmark[]> allBenchmarks, IEnumerable <string> allNames)
        {
            // Use the first job's benchmarks as the reference for the rows:
            var firstBenchmarks = allBenchmarks.FirstOrDefault();

            if (firstBenchmarks == null || firstBenchmarks.Length < 1)
            {
                return;
            }

            var summaries = new Dictionary <string, List <BenchmarkSummary> >();

            foreach (var benchmark in firstBenchmarks)
            {
                summaries[benchmark.FullName] = new List <BenchmarkSummary>();
            }

            foreach (var benchmarks in allBenchmarks)
            {
                foreach (var benchmark in benchmarks)
                {
                    summaries[benchmark.FullName].Add(new BenchmarkSummary()
                    {
                        Name                         = benchmark.FullName,
                        MeanNanoseconds              = benchmark.Statistics.Mean,
                        StandardErrorNanoseconds     = benchmark.Statistics.StandardError,
                        StandardDeviationNanoseconds = benchmark.Statistics.StandardDeviation,
                        MedianNanoseconds            = benchmark.Statistics.Median,
                        Gen0                         = benchmark.Memory?.Gen0Collections ?? 0,
                        Gen1                         = benchmark.Memory?.Gen1Collections ?? 0,
                        Gen2                         = benchmark.Memory?.Gen2Collections ?? 0,
                        AllocatedBytes               = benchmark.Memory?.BytesAllocatedPerOperation ?? 0
                    });
                }
            }

            // Simplfy the benchmarks' names where possible to remove prefixes that
            // are all the same to reduce the width of the first column of the table
            // to the shortest unique string required across all benchmarks.
            var nameSegments = summaries.Keys.ToDictionary(key => key, value => value.Split('.'));

            while (true)
            {
                var areAllFirstSegmentsTheSame = nameSegments.Values
                                                 .Select(segments => segments[0])
                                                 .Distinct()
                                                 .Count() == 1;

                if (!areAllFirstSegmentsTheSame)
                {
                    // The names cannot be simplified further
                    break;
                }

                foreach (var pair in nameSegments)
                {
                    nameSegments[pair.Key] = pair.Value.Skip(1).ToArray();
                }
            }

            // Map the full names to their simplified name
            var simplifiedNames = nameSegments.ToDictionary(key => key.Key, value => string.Join(".", value.Value));

            var anyAllocations = summaries.Values
                                 .SelectMany(list => list)
                                 .Select(summary => summary.AllocatedBytes)
                                 .Any(allocatedBytes => allocatedBytes > 0);

            // Name + baseline mean (firstBenchmarks) + (other benchmarks' mean * 2 (value + ratio)) +
            // baseline allocations + (other benchmarks' mean * 2 (value + ratio))
            var otherCount = allNames.Count() - 1;
            var table      = new ResultTable(1 + 1 + (anyAllocations ? 1 : 0) + (otherCount * (anyAllocations ? 4 : 2)));

            var firstName = allNames.First();

            table.Headers.Add("benchmark");
            table.Headers.Add($"mean ({firstName})");

            foreach (var name in allNames.Skip(1))
            {
                table.Headers.Add($"mean ({name})");
                table.Headers.Add("ratio");
            }

            if (anyAllocations)
            {
                table.Headers.Add($"allocated ({firstName})");

                foreach (var name in allNames.Skip(1))
                {
                    table.Headers.Add($"allocated ({name})");
                    table.Headers.Add("ratio");
                }
            }

            foreach (var benchmark in summaries.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Value))
            {
                var firstBenchmark = benchmark.First();
                var simplifiedName = simplifiedNames[firstBenchmark.Name];

                var benchmarks = summaries[firstBenchmark.Name];

                var row  = table.AddRow();
                var cell = new Cell();
                cell.Elements.Add(new CellElement()
                {
                    Text = simplifiedName, Alignment = CellTextAlignment.Left
                });
                row.Add(cell);

                AddCells(row, summary => summary.MeanNanoseconds, UnitType.Time, benchmarks);

                if (anyAllocations)
                {
                    AddCells(row, summary => summary.AllocatedBytes, UnitType.Size, benchmarks);
                }
            }

            Console.WriteLine("```md"); // Format as a GitHub-flavored Markdown table

            table.Render(Console.Out);

            Console.WriteLine("```");

            void AddCells(
                List <Cell> row,
                Func <BenchmarkSummary, object> valueFactory,
                UnitType unitType,
                List <BenchmarkSummary> summaries)
            {
                var rawValues = summaries
                                .Select(summary => valueFactory(summary))
                                .Select(value => Convert.ToDouble(value))
                                .ToArray();

                var precision = PrecisionHelper.GetPrecision(rawValues);
                var sizeUnit  = unitType == UnitType.Size ? SizeUnit.GetBestSizeUnit(rawValues) : null;
                var timeUnit  = unitType == UnitType.Time ? TimeUnit.GetBestTimeUnit(rawValues) : null;

                var units = unitType switch
                {
                    UnitType.Size => sizeUnit.Name,
                    UnitType.Time => timeUnit.Name,
                    _ => string.Empty
                };

                var baseline = summaries[0];

                for (var i = 0; i < summaries.Count; i++)
                {
                    var measure  = rawValues[i];
                    var previous = rawValues[0];

                    var ratio = measure == 0
                    ? 0
                    : measure / previous;

                    var formattedValue = unitType switch
                    {
                        UnitType.Size => new SizeValue((long)measure).ToString(sizeUnit),
                        UnitType.Time => new TimeInterval(measure).ToString(timeUnit, precision),
                        _ => measure.ToString("N" + precision, CultureInfo.InvariantCulture)
                    };

                    var cell = new Cell();
                    cell.Elements.Add(new CellElement
                    {
                        Text      = $"{formattedValue} {units}",
                        Alignment = CellTextAlignment.Right
                    });
                    row.Add(cell);

                    // Don't render the ratio on baseline benchmark
                    if (summaries[i] != baseline)
                    {
                        row.Add(cell = new Cell());

                        if (measure != 0)
                        {
                            cell.Elements.Add(new CellElement
                            {
                                Text      = ratio.ToString("N2", CultureInfo.InvariantCulture),
                                Alignment = CellTextAlignment.Right
                            });
                        }
                    }
                }
            }
        }
Beispiel #40
0
 protected bool ShouldSerializeSizeUnit()
 {
     return(!SizeUnit.Equals(GetDefaultPropertyValue("SizeUnit", SizeUnit)));
 }
Beispiel #41
0
 public static double Convert(long value, SizeUnit from, SizeUnit to)
 => value * (double)from.ByteAmount / (to ?? GetBestSizeUnit(value)).ByteAmount;