Skip to content

Commit

Permalink
Fix - incorrect table markdown #2545 (#2565)
Browse files Browse the repository at this point in the history
* Fix -  incorrect table markdown #2545

* Hide Column Table Markdown test case

* columHidingRules support for CreateSummary in MockFactory

* made the test case more generic to support hide columns attribute

* Update tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterVerifyTests.cs

---------

Co-authored-by: Tim Cassell <35501420+timcassell@users.noreply.github.com>
  • Loading branch information
AumkarGorde and timcassell committed Apr 28, 2024
1 parent d98a1d2 commit 205ce61
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Exporters/MarkdownExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ private void PrintTable(SummaryTable table, ILogger logger)
logger.WriteStatistic(ColumnsStartWithSeparator ? TableHeaderSeparator.TrimStart().TrimEnd() + "-" : "-");

logger.WriteLineStatistic(string.Join("",
table.Columns.Where(c => c.NeedToShow).Select(column =>
table.Columns.Where(c => c.NeedToShow).Select((column, index) =>
new string('-', column.Width - 1) + GetHeaderSeparatorIndicator(column.OriginalColumn.IsNumeric) +
GetHeaderSeparatorColumnDivider(column.Index, table.ColumnCount))));
GetHeaderSeparatorColumnDivider(index, table.Columns.Where(c => c.NeedToShow).Count()))));
}

int rowCounter = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using JetBrains.Annotations;
using VerifyXunit;
using Xunit;
using BenchmarkDotNet.Columns;
using System.Reflection;

namespace BenchmarkDotNet.Tests.Exporters
{
Expand All @@ -40,9 +42,8 @@ public Task GroupExporterTest(Type benchmarkType)

var logger = new AccumulationLogger();
logger.WriteLine("=== " + benchmarkType.Name + " ===");

var exporter = MarkdownExporter.Mock;
var summary = MockFactory.CreateSummary(benchmarkType);
var summary = MockFactory.CreateSummary(benchmarkType, benchmarkType.GetCustomAttribute<HideColumnsAttribute>()?.Config.GetColumnHidingRules().ToArray() ?? []);
exporter.ExportToLog(summary, logger);

var validator = BaselineValidator.FailOnError;
Expand Down Expand Up @@ -219,8 +220,8 @@ public class JobBaseline_MethodsParamsJobs
[SimpleJob(id: "Job1", baseline: true), SimpleJob(id: "Job2")]
public class MethodJobBaseline_MethodsJobs
{
[Benchmark(Baseline = true)] public void Foo() {}
[Benchmark] public void Bar() {}
[Benchmark(Baseline = true)] public void Foo() { }
[Benchmark] public void Bar() { }
}

[RankColumn, LogicalGroupColumn, BaselineColumn]
Expand All @@ -229,25 +230,25 @@ public class MethodJobBaseline_MethodsJobsParams
{
[Params(2, 10), UsedImplicitly] public int Param;

[Benchmark(Baseline = true)] public void Foo() {}
[Benchmark] public void Bar() {}
[Benchmark(Baseline = true)] public void Foo() { }
[Benchmark] public void Bar() { }
}

/* Invalid */

[RankColumn, LogicalGroupColumn, BaselineColumn]
public class Invalid_TwoMethodBaselines
{
[Benchmark(Baseline = true)] public void Foo() {}
[Benchmark(Baseline = true)] public void Bar() {}
[Benchmark(Baseline = true)] public void Foo() { }
[Benchmark(Baseline = true)] public void Bar() { }
}

[RankColumn, LogicalGroupColumn, BaselineColumn]
[SimpleJob(id: "Job1", baseline: true), SimpleJob(id: "Job2", baseline: true)]
public class Invalid_TwoJobBaselines
{
[Benchmark] public void Foo() {}
[Benchmark] public void Bar() {}
[Benchmark] public void Foo() { }
[Benchmark] public void Bar() { }
}

/* Escape Params */
Expand All @@ -260,6 +261,13 @@ public class Escape_ParamsAndArguments
[Benchmark] public void Foo(char charArg) {}
[Benchmark] public void Bar() {}
}

/* Hide Column */
[HideColumns(Column.StdDev)]
public class HideColumns_TableMarkDown
{
[Benchmark] public void Foo() { }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=== HideColumns_TableMarkDown ===

BenchmarkDotNet v0.10.x-mock, Microsoft Windows NT 10.0.x.mock (Hyper-V)
MockIntel Core i7-6700HQ CPU 2.60GHz (Max: 3.10GHz), 1 CPU, 8 logical and 4 physical cores
Frequency: 2531248 Hz, Resolution: 395.062 ns, Timer: TSC
[Host] : Clr 4.0.x.mock, 64mock RyuJIT-v4.6.x.mock CONFIGURATION
DefaultJob : extra output line

StdDev=8.80 ns

Method | Mean | Error |
------- |---------:|--------:|
Foo | 114.5 ns | 5.88 ns |

Errors: 0
4 changes: 2 additions & 2 deletions tests/BenchmarkDotNet.Tests/Mocks/MockFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace BenchmarkDotNet.Tests.Mocks
{
public static class MockFactory
{
public static Summary CreateSummary(Type benchmarkType)
public static Summary CreateSummary(Type benchmarkType, params IColumnHidingRule[] columHidingRules)
{
var runInfo = BenchmarkConverter.TypeToBenchmarks(benchmarkType);
return new Summary(
Expand All @@ -36,7 +36,7 @@ public static Summary CreateSummary(Type benchmarkType)
TimeSpan.FromMinutes(1),
TestCultureInfo.Instance,
ImmutableArray<ValidationError>.Empty,
ImmutableArray<IColumnHidingRule>.Empty);
ImmutableArray.Create<IColumnHidingRule>(columHidingRules));
}

public static Summary CreateSummary(IConfig config) => new Summary(
Expand Down

0 comments on commit 205ce61

Please sign in to comment.