Skip to content

Commit

Permalink
polishing the code, #699
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Mar 24, 2018
1 parent b958a1b commit 4f5714c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
30 changes: 19 additions & 11 deletions src/BenchmarkDotNet/Environments/Runtime.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace BenchmarkDotNet.Environments
using System;

namespace BenchmarkDotNet.Environments
{
public abstract class Runtime
public abstract class Runtime : IEquatable<Runtime>
{
/// <summary>
/// Full .NET Framework (Windows only)
Expand All @@ -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
Expand All @@ -43,17 +48,20 @@ public CoreRuntime() : base("Core")
}
}

public class MonoRuntime : Runtime
public class MonoRuntime : Runtime, IEquatable<MonoRuntime>
{
public string CustomPath { get; }

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);
}
}
10 changes: 4 additions & 6 deletions src/BenchmarkDotNet/Running/BuildPartition.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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; }
Expand All @@ -24,7 +22,7 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)

/// <summary>
/// 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
/// </summary>
public Benchmark RepresentativeBenchmark { get; }

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4f5714c

Please sign in to comment.