Skip to content

Commit 8380003

Browse files
Hide columns for multiple runtime (#1621)
* #1603: Don't display Job and Toolchain column when running benchmarks for multiple runtimes * pedantic improvements: rename IsMultipleRuntime to IsMultipleRuntimes make it Lazy don't use Count() when Length is available * use simpler way of checking whether Id was assigned by the user in explicit way Co-authored-by: [email protected] <marc90> Co-authored-by: Adam Sitnik <[email protected]>
1 parent 1424cf8 commit 8380003

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/BenchmarkDotNet/Columns/JobCharacteristicColumn.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ private JobCharacteristicColumn(Characteristic characteristic)
2828

2929
public string Id { get; }
3030
public string ColumnName { get; }
31-
public bool IsAvailable(Summary summary) => true;
3231
public bool AlwaysShow => false;
3332
public ColumnCategory Category => ColumnCategory.Job;
3433
public int PriorityInCategory => 0;
@@ -38,6 +37,23 @@ private JobCharacteristicColumn(Characteristic characteristic)
3837

3938
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => !benchmarkCase.Job.HasValue(characteristic);
4039

40+
public bool IsAvailable(Summary summary)
41+
{
42+
if (summary.IsMultipleRuntimes)
43+
{
44+
if (nameof(Toolchains.Toolchain).Equals(ColumnName))
45+
{
46+
return false;
47+
}
48+
if (nameof(Job).Equals(ColumnName))
49+
{
50+
return summary.BenchmarksCases.Any(x => x.Job.HasValue(CharacteristicObject.IdCharacteristic));
51+
}
52+
}
53+
54+
return true;
55+
}
56+
4157
public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
4258
{
4359
if (!benchmarkCase.Job.HasValue(characteristic) && EnvironmentResolver.Instance.CanResolve(characteristic))

src/BenchmarkDotNet/Reports/Summary.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ public class Summary
3030
[PublicAPI] public ImmutableArray<BenchmarkCase> BenchmarksCases { get; }
3131
[PublicAPI] public ImmutableArray<BenchmarkReport> Reports { get; }
3232

33-
private ImmutableDictionary<BenchmarkCase, BenchmarkReport> ReportMap {get; }
34-
private BaseliningStrategy BaseliningStrategy {get; }
35-
3633
internal DisplayPrecisionManager DisplayPrecisionManager { get; }
3734

35+
private ImmutableDictionary<BenchmarkCase, BenchmarkReport> ReportMap { get; }
36+
private BaseliningStrategy BaseliningStrategy { get; }
37+
private bool? isMultipleRuntimes;
38+
3839
public Summary(
3940
string title,
4041
ImmutableArray<BenchmarkReport> reports,
@@ -75,6 +76,9 @@ public Summary(
7576

7677
public int GetNumberOfExecutedBenchmarks() => Reports.Count(report => report.ExecuteResults.Any(result => result.FoundExecutable));
7778

79+
public bool IsMultipleRuntimes
80+
=> isMultipleRuntimes ??= BenchmarksCases.Length > 1 ? BenchmarksCases.Select(benchmark => benchmark.GetRuntime()).Distinct().Count() > 1 : false;
81+
7882
internal static Summary NothingToRun(string title, string resultsDirectoryPath, string logFilePath)
7983
=> new Summary(title, ImmutableArray<BenchmarkReport>.Empty, HostEnvironmentInfo.GetCurrent(), resultsDirectoryPath, logFilePath, TimeSpan.Zero, DefaultCultureInfo.Instance, ImmutableArray<ValidationError>.Empty);
8084

0 commit comments

Comments
 (0)