Skip to content

Commit 34817bf

Browse files
Change DisassemblyDiagnoser to use byte unit always (#1855)
1 parent 7b02117 commit 34817bf

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

src/BenchmarkDotNet/Columns/MetricColumn.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyl
3232
return "-";
3333

3434
var cultureInfo = summary.GetCultureInfo();
35+
36+
if (style.PrintUnitsInContent && descriptor.UnitType == UnitType.CodeSize)
37+
return SizeValue.FromBytes((long)metric.Value).ToString(style.CodeSizeUnit, cultureInfo, descriptor.NumberFormat);
3538
if (style.PrintUnitsInContent && descriptor.UnitType == UnitType.Size)
3639
return SizeValue.FromBytes((long)metric.Value).ToString(style.SizeUnit, cultureInfo, descriptor.NumberFormat);
3740
if (style.PrintUnitsInContent && descriptor.UnitType == UnitType.Time)

src/BenchmarkDotNet/Columns/UnitType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public enum UnitType
44
{
55
Dimensionless,
66
Time,
7-
Size
7+
Size,
8+
CodeSize
89
}
910
}

src/BenchmarkDotNet/Disassemblers/DisassemblyDiagnoser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ private class NativeCodeSizeMetricDescriptor : IMetricDescriptor
165165
public string Id => "Native Code Size";
166166
public string DisplayName => "Code Size";
167167
public string Legend => "Native code size of the disassembled method(s)";
168-
public string NumberFormat => "0.##";
169-
public UnitType UnitType => UnitType.Size;
168+
public string NumberFormat => "N0";
169+
public UnitType UnitType => UnitType.CodeSize;
170170
public string Unit => SizeUnit.B.Name;
171171
public bool TheGreaterTheBetter => false;
172172
public int PriorityInCategory => 0;

src/BenchmarkDotNet/Extensions/CommonExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public static string GetColumnTitle(this IColumn column, SummaryStyle style)
1919

2020
switch (column.UnitType)
2121
{
22+
case UnitType.CodeSize:
23+
return $"{column.ColumnName} [{style.CodeSizeUnit.Name}]";
2224
case UnitType.Size:
2325
return $"{column.ColumnName} [{style.SizeUnit.Name}]";
2426
case UnitType.Time:

src/BenchmarkDotNet/Reports/SummaryStyle.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class SummaryStyle : IEquatable<SummaryStyle>
1919
public bool PrintZeroValuesInContent { get; }
2020
public int MaxParameterColumnWidth { get; }
2121
public SizeUnit SizeUnit { get; }
22+
internal SizeUnit CodeSizeUnit { get; }
2223
public TimeUnit TimeUnit { get; }
2324
[NotNull]
2425
public CultureInfo CultureInfo { get; }
@@ -39,6 +40,7 @@ public SummaryStyle([CanBeNull] CultureInfo cultureInfo, bool printUnitsInHeader
3940
PrintZeroValuesInContent = printZeroValuesInContent;
4041
MaxParameterColumnWidth = maxParameterColumnWidth;
4142
RatioStyle = ratioStyle;
43+
CodeSizeUnit = SizeUnit.B;
4244
}
4345

4446
public SummaryStyle WithTimeUnit(TimeUnit timeUnit)
@@ -70,6 +72,7 @@ public bool Equals(SummaryStyle other)
7072
&& PrintUnitsInContent == other.PrintUnitsInContent
7173
&& PrintZeroValuesInContent == other.PrintZeroValuesInContent
7274
&& Equals(SizeUnit, other.SizeUnit)
75+
&& Equals(SizeUnit, other.CodeSizeUnit)
7376
&& Equals(TimeUnit, other.TimeUnit)
7477
&& MaxParameterColumnWidth == other.MaxParameterColumnWidth
7578
&& RatioStyle == other.RatioStyle;
@@ -85,6 +88,7 @@ public override int GetHashCode()
8588
hashCode = (hashCode * 397) ^ PrintUnitsInContent.GetHashCode();
8689
hashCode = (hashCode * 397) ^ PrintZeroValuesInContent.GetHashCode();
8790
hashCode = (hashCode * 397) ^ (SizeUnit != null ? SizeUnit.GetHashCode() : 0);
91+
hashCode = (hashCode * 397) ^ (CodeSizeUnit != null ? CodeSizeUnit.GetHashCode() : 0);
8892
hashCode = (hashCode * 397) ^ (TimeUnit != null ? TimeUnit.GetHashCode() : 0);
8993
hashCode = (hashCode * 397) ^ MaxParameterColumnWidth;
9094
hashCode = (hashCode * 397) ^ RatioStyle.GetHashCode();

0 commit comments

Comments
 (0)