Skip to content

Commit

Permalink
Hide columns for multiple runtime (#1621)
Browse files Browse the repository at this point in the history
* #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]>
  • Loading branch information
marcnet80 and adamsitnik authored Aug 25, 2022
1 parent 1424cf8 commit 8380003
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/BenchmarkDotNet/Columns/JobCharacteristicColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private JobCharacteristicColumn(Characteristic characteristic)

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

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

public bool IsAvailable(Summary summary)
{
if (summary.IsMultipleRuntimes)
{
if (nameof(Toolchains.Toolchain).Equals(ColumnName))
{
return false;
}
if (nameof(Job).Equals(ColumnName))
{
return summary.BenchmarksCases.Any(x => x.Job.HasValue(CharacteristicObject.IdCharacteristic));
}
}

return true;
}

public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
{
if (!benchmarkCase.Job.HasValue(characteristic) && EnvironmentResolver.Instance.CanResolve(characteristic))
Expand Down
10 changes: 7 additions & 3 deletions src/BenchmarkDotNet/Reports/Summary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public class Summary
[PublicAPI] public ImmutableArray<BenchmarkCase> BenchmarksCases { get; }
[PublicAPI] public ImmutableArray<BenchmarkReport> Reports { get; }

private ImmutableDictionary<BenchmarkCase, BenchmarkReport> ReportMap {get; }
private BaseliningStrategy BaseliningStrategy {get; }

internal DisplayPrecisionManager DisplayPrecisionManager { get; }

private ImmutableDictionary<BenchmarkCase, BenchmarkReport> ReportMap { get; }
private BaseliningStrategy BaseliningStrategy { get; }
private bool? isMultipleRuntimes;

public Summary(
string title,
ImmutableArray<BenchmarkReport> reports,
Expand Down Expand Up @@ -75,6 +76,9 @@ public Summary(

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

public bool IsMultipleRuntimes
=> isMultipleRuntimes ??= BenchmarksCases.Length > 1 ? BenchmarksCases.Select(benchmark => benchmark.GetRuntime()).Distinct().Count() > 1 : false;

internal static Summary NothingToRun(string title, string resultsDirectoryPath, string logFilePath)
=> new Summary(title, ImmutableArray<BenchmarkReport>.Empty, HostEnvironmentInfo.GetCurrent(), resultsDirectoryPath, logFilePath, TimeSpan.Zero, DefaultCultureInfo.Instance, ImmutableArray<ValidationError>.Empty);

Expand Down

0 comments on commit 8380003

Please sign in to comment.