diff --git a/src/BenchmarkDotNet/Environments/Runtime.cs b/src/BenchmarkDotNet/Environments/Runtime.cs index 0dc7b87865..5d912a073e 100644 --- a/src/BenchmarkDotNet/Environments/Runtime.cs +++ b/src/BenchmarkDotNet/Environments/Runtime.cs @@ -1,6 +1,8 @@ -namespace BenchmarkDotNet.Environments +using System; + +namespace BenchmarkDotNet.Environments { - public abstract class Runtime + public abstract class Runtime : IEquatable { /// /// Full .NET Framework (Windows only) @@ -21,12 +23,15 @@ public abstract class Runtime public string Name { get; } - protected Runtime(string name) - { - Name = name; - } + protected Runtime(string name) => Name = name; public override string ToString() => Name; + + public bool Equals(Runtime other) => other != null && other.Name == Name; // for this type this is enough + + public override bool Equals(object obj) => obj is Runtime other && Equals(other); + + public override int GetHashCode() => Name.GetHashCode(); } public class ClrRuntime : Runtime @@ -43,7 +48,7 @@ public CoreRuntime() : base("Core") } } - public class MonoRuntime : Runtime + public class MonoRuntime : Runtime, IEquatable { public string CustomPath { get; } @@ -51,9 +56,12 @@ public MonoRuntime() : base("Mono") { } - public MonoRuntime(string name, string customPath) : base(name) - { - CustomPath = customPath; - } + public MonoRuntime(string name, string customPath) : base(name) => CustomPath = customPath; + + public override bool Equals(object obj) => obj is MonoRuntime other && Equals(other); + + public bool Equals(MonoRuntime other) => other != null && Name == other.Name && CustomPath == other.CustomPath; + + public override int GetHashCode() => Name.GetHashCode() ^ (CustomPath?.GetHashCode() ?? 0); } } \ No newline at end of file diff --git a/src/BenchmarkDotNet/Running/BuildPartition.cs b/src/BenchmarkDotNet/Running/BuildPartition.cs index 1cb9936f78..63b72abc37 100644 --- a/src/BenchmarkDotNet/Running/BuildPartition.cs +++ b/src/BenchmarkDotNet/Running/BuildPartition.cs @@ -1,10 +1,8 @@ using System; -using System.Linq; using BenchmarkDotNet.Characteristics; using BenchmarkDotNet.Environments; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Portability; -using BenchmarkDotNet.Toolchains; namespace BenchmarkDotNet.Running { @@ -13,9 +11,9 @@ public class BuildPartition public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver) { Resolver = resolver; - RepresentativeBenchmark = benchmarks.Select(info => info.Benchmark).FirstOrDefault(); + RepresentativeBenchmark = benchmarks[0].Benchmark; Benchmarks = benchmarks; - ProgramName = Guid.NewGuid().ToString(); // todo: figure out some nice name (first job.Folder?) + ProgramName = benchmarks[0].Config.KeepBenchmarkFiles ? RepresentativeBenchmark.Job.FolderInfo : Guid.NewGuid().ToString(); } public BenchmarkBuildInfo[] Benchmarks { get; } @@ -24,7 +22,7 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver) /// /// the benchmarks are groupped by the build settings - /// so you can use this benchmark to get the settings + /// so you can use this benchmark to get the runtime settings /// public Benchmark RepresentativeBenchmark { get; } @@ -42,6 +40,6 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver) ? RepresentativeBenchmark.Job.Env.Runtime : RuntimeInformation.GetCurrentRuntime(); - public override string ToString() => $"{Runtime}-{Platform}-{Jit}-{RepresentativeBenchmark.Job.GetToolchain()}"; + public override string ToString() => RepresentativeBenchmark.Job.DisplayInfo; } } \ No newline at end of file diff --git a/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs b/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs index bf8880e3f9..cb84ebaa66 100644 --- a/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs +++ b/src/BenchmarkDotNet/Toolchains/Parameters/ExecuteParameters.cs @@ -9,8 +9,7 @@ namespace BenchmarkDotNet.Toolchains.Parameters { public class ExecuteParameters { - public ExecuteParameters(BuildResult buildResult, Benchmark benchmark, BenchmarkId benchmarkId, ILogger logger, IResolver resolver, IConfig config, - IDiagnoser diagnoser = null) + public ExecuteParameters(BuildResult buildResult, Benchmark benchmark, BenchmarkId benchmarkId, ILogger logger, IResolver resolver, IConfig config, IDiagnoser diagnoser = null) { BuildResult = buildResult; Benchmark = benchmark;