Skip to content

Commit

Permalink
Remove duplicated jobs when creating immutable config (#2202)
Browse files Browse the repository at this point in the history
  • Loading branch information
YegorStepanov authored Nov 21, 2022
1 parent ad8e9b2 commit ccbaf08
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Configs/ImmutableConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static ImmutableHashSet<IValidator> GetValidators(IEnumerable<IValidator
/// </summary>
private static IReadOnlyList<Job> GetRunnableJobs(IEnumerable<Job> jobs)
{
var unique = jobs.Distinct().ToArray();
var unique = jobs.Distinct(JobComparer.Instance).ToArray();
var result = new List<Job>();

foreach (var standardJob in unique.Where(job => !job.Meta.IsMutator && !job.Meta.IsDefault))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ [PublicAPI] protected string GetConfigurationFlag() => Configuration == RuntimeI
? ""
: Configuration;

[PublicAPI] protected string GetDebuggerFlag() => HasAttachedDebugger ? " [AttachedDebugger]" : "";
[PublicAPI] protected string GetDebuggerFlag() => HasAttachedDebugger ? "[AttachedDebugger]" : "";
[PublicAPI] protected string GetGcServerFlag() => IsServerGC ? "Server" : "Workstation";
[PublicAPI] protected string GetGcConcurrentFlag() => IsConcurrentGC ? "Concurrent" : "Non-concurrent";

Expand Down
13 changes: 13 additions & 0 deletions tests/BenchmarkDotNet.Tests/Configs/ImmutableConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ namespace BenchmarkDotNet.Tests.Configs
{
public class ImmutableConfigTests
{
[Fact]
public void DuplicateJobsAreExcluded()
{
var mutable = ManualConfig.CreateEmpty();

mutable.AddJob(new Job());
mutable.AddJob(new Job());

var final = ImmutableConfigBuilder.Create(mutable);

Assert.Single(final.GetJobs());
}

[Fact]
public void DuplicateColumnProvidersAreExcluded()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,6 @@ public void CustomClrBuildJobsAreGroupedByVersion()
Assert.Equal(3 * 2, grouping.Count()); // (M1 + M2 + M3) * (Plain1 + Plain2)
}

[Fact]
public void CustomNuGetJobsWithSamePackageVersionAreGroupedTogether()
{
var job1 = Job.Default.WithNuGet("AutoMapper", "7.0.1");
var job2 = Job.Default.WithNuGet("AutoMapper", "7.0.1");

var config = ManualConfig.Create(DefaultConfig.Instance)
.AddJob(job1)
.AddJob(job2);

var benchmarks1 = BenchmarkConverter.TypeToBenchmarks(typeof(Plain1), config);
var benchmarks2 = BenchmarkConverter.TypeToBenchmarks(typeof(Plain2), config);

var grouped = benchmarks1.BenchmarksCases.Union(benchmarks2.BenchmarksCases)
.GroupBy(benchmark => benchmark, new BenchmarkPartitioner.BenchmarkRuntimePropertiesComparer())
.ToArray();

Assert.Single(grouped); // 7.0.1

foreach (var grouping in grouped)
Assert.Equal(2 * 3 * 2, grouping.Count()); // ((job1 + job2) * (M1 + M2 + M3) * (Plain1 + Plain2)
}

[Fact]
public void CustomNuGetJobsAreGroupedByPackageVersion()
{
Expand Down

0 comments on commit ccbaf08

Please sign in to comment.