Skip to content

Commit

Permalink
remove Framework settings from Jobs, fixes #194
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Jul 6, 2016
1 parent 61b4c18 commit 9761182
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 70 deletions.
2 changes: 1 addition & 1 deletion BenchmarkDotNet.IntegrationTests/MultipleRuntimesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void SingleBenchmarkCanBeExecutedForMultpleRuntimes()
.Run<C>(
ManualConfig.CreateEmpty()
.With(Job.Dry.With(Runtime.Core))
.With(Job.Dry.With(Runtime.Clr).With(Framework.V46))
.With(Job.Dry.With(Runtime.Clr))
.With(new OutputLogger(output)));

Assert.True(summary.Reports
Expand Down
2 changes: 1 addition & 1 deletion BenchmarkDotNet.Samples/Algorithms/Algo_Md5VsSha256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class AllWindowsRuntimesConfig : ManualConfig
{
public AllWindowsRuntimesConfig()
{
Add(Job.Default.With(Runtime.Clr).With(Jit.RyuJit).With(Jobs.Framework.V40));
Add(Job.Default.With(Runtime.Clr).With(Jit.RyuJit));
Add(Job.Default.With(Runtime.Core).With(Jit.RyuJit));
}
}
Expand Down
2 changes: 1 addition & 1 deletion BenchmarkDotNet.Samples/Intro/IntroRuntimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private class MultipleRuntimesConfig : ManualConfig
{
public MultipleRuntimesConfig()
{
Add(Job.Dry.With(Runtime.Clr).With(Jit.RyuJit).With(Jobs.Framework.V40)); // framework for Clr must be set in explicit way
Add(Job.Dry.With(Runtime.Clr).With(Jit.RyuJit));
Add(Job.Dry.With(Runtime.Core).With(Jit.RyuJit));
}
}
Expand Down
3 changes: 2 additions & 1 deletion BenchmarkDotNet/Columns/PropertyColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class PropertyColumn : IColumn
public static readonly IColumn Mode = new PropertyColumn("Mode", benchmark => benchmark.Job.Mode.ToString());
public static readonly IColumn Platform = new PropertyColumn("Platform", benchmark => benchmark.Job.Platform.ToString());
public static readonly IColumn Jit = new PropertyColumn("Jit", benchmark => benchmark.Job.Jit.ToString());
public static readonly IColumn Framework = new PropertyColumn("Framework", benchmark => benchmark.Job.Framework.ToString());
[Obsolete("Framework setting is not supported anymore, see https://github.com/PerfDotNet/BenchmarkDotNet/issues/194 for more details", true)]
public static readonly IColumn Framework = new PropertyColumn("Framework", benchmark => null);
public static readonly IColumn Toolchain = new PropertyColumn("Toolchain", benchmark => Toolchains.Toolchain.GetToolchain(benchmark.Job).Name);
public static readonly IColumn Runtime = new PropertyColumn("Runtime", benchmark => benchmark.Job.Runtime.ToString());
public static readonly IColumn GarbageCollection = new PropertyColumn("GarbageCollection", benchmark => benchmark.Job.GarbageCollection?.ToString());
Expand Down
1 change: 0 additions & 1 deletion BenchmarkDotNet/Configs/DefaultConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public IEnumerable<IColumn> GetColumns()
yield return PropertyColumn.Mode;
yield return PropertyColumn.Platform;
yield return PropertyColumn.Jit;
yield return PropertyColumn.Framework;
yield return PropertyColumn.Toolchain;
yield return PropertyColumn.Runtime;
yield return PropertyColumn.GarbageCollection;
Expand Down
1 change: 0 additions & 1 deletion BenchmarkDotNet/Exporters/CsvMeasurementsExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public MeasurementColumn(string title, Func<Summary, BenchmarkReport, Measuremen
new MeasurementColumn("JobMode", (summary, report, m) => report.Benchmark.Job.Mode.ToString()),
new MeasurementColumn("JobPlatform", (summary, report, m) => report.Benchmark.Job.Platform.ToString()),
new MeasurementColumn("JobJit", (summary, report, m) => report.Benchmark.Job.Jit.ToString()),
new MeasurementColumn("JobFramework", (summary, report, m) => report.Benchmark.Job.Framework.ToString()),
new MeasurementColumn("JobToolchain", (summary, report, m) => Toolchains.Toolchain.GetToolchain(report.Benchmark.Job).Name),
new MeasurementColumn("JobRuntime", (summary, report, m) => report.Benchmark.Job.Runtime.ToString()),

Expand Down
8 changes: 0 additions & 8 deletions BenchmarkDotNet/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using BenchmarkDotNet.Jobs;

namespace BenchmarkDotNet.Extensions
Expand All @@ -23,13 +22,6 @@ public static string ToConfig(this Platform platform)
}
}

public static string ToConfig(this Framework framework)
{
var number = framework.ToString().Substring(1);
var numberArray = number.ToCharArray().Select(c => c.ToString()).ToArray();
return "v" + string.Join(".", numberArray);
}

public static string ToConfig(this Jit jit)
{
return jit == Jit.LegacyJit ? "1" : "0";
Expand Down
12 changes: 1 addition & 11 deletions BenchmarkDotNet/Jobs/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@

namespace BenchmarkDotNet.Jobs
{
// TODO: Drop V35 in next version
[Obsolete("Framework setting is not supported anymore, see https://github.com/PerfDotNet/BenchmarkDotNet/issues/194 for more details", true)]
public enum Framework
{
Host,
[Obsolete("BenchmarkDotNet does not support .NET 3.5", true)]
V35,
V40,
V45,
V451,
V452,
V46,
V461,
V462
}
}
1 change: 0 additions & 1 deletion BenchmarkDotNet/Jobs/IJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public interface IJob : IEquatable<IJob>
Mode Mode { get; }
Platform Platform { get; }
Jit Jit { get; }
Framework Framework { get; }
IToolchain Toolchain { get; }
Runtime Runtime { get; }
GarbageCollection GarbageCollection { get; }
Expand Down
1 change: 0 additions & 1 deletion BenchmarkDotNet/Jobs/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class Job : IJob
public Mode Mode { get; set; } = Mode.Throughput;
public Platform Platform { get; set; } = Platform.Host;
public Jit Jit { get; set; } = Jit.Host;
public Framework Framework { get; set; } = Framework.Host;
public IToolchain Toolchain { get; set; }
public Runtime Runtime { get; set; } = Runtime.Host;
public GarbageCollection GarbageCollection { get; set; } = GarbageCollection.Default;
Expand Down
3 changes: 0 additions & 3 deletions BenchmarkDotNet/Jobs/JobExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public static class JobExtensions
public static IJob With(this IJob job, Mode mode) => job.With(j => j.Mode = mode);
public static IJob With(this IJob job, Platform platform) => job.With(j => j.Platform = platform);
public static IJob With(this IJob job, Jit jit) => job.With(j => j.Jit = jit);
public static IJob With(this IJob job, Framework framework) => job.With(j => j.Framework = framework);
public static IJob With(this IJob job, IToolchain toolchain) => job.With(j => j.Toolchain = toolchain);
public static IJob With(this IJob job, Runtime runtime) => job.With(j => j.Runtime = runtime);
public static IJob With(this IJob job, GarbageCollection garbageCollection) => job.With(j => j.GarbageCollection = garbageCollection);
Expand All @@ -35,7 +34,6 @@ public static Property[] GetAllProperties(this IJob job)
new Property(nameof(Mode), job.Mode.ToString()),
new Property(nameof(Platform), job.Platform.ToString()),
new Property(nameof(Jit), job.Jit.ToString()),
new Property(nameof(Framework), job.Framework.ToString()),
new Property(nameof(Runtime), job.Runtime.ToString()),
new Property(nameof(GarbageCollection), job.GarbageCollection?.ToString()),
new Property(nameof(IJob.WarmupCount), job.WarmupCount.ToString()),
Expand Down Expand Up @@ -90,7 +88,6 @@ private static IJob With(this IJob job, Action<Job> set)
Jit = job.Jit,
Platform = job.Platform,
Toolchain = job.Toolchain,
Framework = job.Framework,
Runtime = job.Runtime,
GarbageCollection = job.GarbageCollection,
Mode = job.Mode,
Expand Down
35 changes: 8 additions & 27 deletions BenchmarkDotNet/Toolchains/Classic/ClassicToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,27 @@ namespace BenchmarkDotNet.Toolchains.Classic
{
public class ClassicToolchain : Toolchain
{
// In case somebody calls ClassicToolchain from .NET Core process
// we will build the project as 4.6 because it's the most safe way to do it:
// * everybody that uses .NET Core must have VS 2015 installed and 4.6 is part of the installation
// * from 4.6 you can target < 4.6
private const string TargetFrameworkMoniker = "net46";

public static readonly IToolchain Instance = new ClassicToolchain();

private ClassicToolchain()
#if CLASSIC
: base("Classic", new RoslynGenerator(), new RoslynBuilder(), new ClassicExecutor())
#else
: base("Classic", new DotNetCliGenerator(
TargetFrameworkMonikerProvider,
TargetFrameworkMoniker,
extraDependencies: "\"frameworkAssemblies\": { \"System.Runtime\": \"4.0.0.0\" },",
platformProvider: platform => platform.ToConfig(),
imports: "\"portable-net45+win8\""),
new DotNetCliBuilder(TargetFrameworkMonikerProvider),
new DotNetCliBuilder(TargetFrameworkMoniker),
new ClassicExecutor())
#endif
{
}

private static string TargetFrameworkMonikerProvider(Framework framework)
{
switch (framework)
{
case Framework.Host:
throw new ArgumentException("Framework must be set");
case Framework.V40:
return "net40";
case Framework.V45:
return "net45";
case Framework.V451:
return "net451";
case Framework.V452:
return "net452";
case Framework.V46:
return "net46";
case Framework.V461:
return "net461";
case Framework.V462:
return "net462";
default:
throw new ArgumentOutOfRangeException(nameof(framework), framework, null);
}
}
}
}
8 changes: 4 additions & 4 deletions BenchmarkDotNet/Toolchains/Core/CoreToolchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ namespace BenchmarkDotNet.Toolchains.Core
{
public class CoreToolchain : Toolchain
{
private const string TargetFrameworkMoniker = "netcoreapp1.0";

public static readonly IToolchain Instance = new CoreToolchain();

private CoreToolchain()
: base("Core",
new DotNetCliGenerator(
GetTargetFrameworkMoniker,
TargetFrameworkMoniker,
GetExtraDependencies(),
platformProvider: _ => "x64", // dotnet cli supports only x64 compilation now
imports: GetImports(),
runtime: GetRuntime()),
new DotNetCliBuilder(GetTargetFrameworkMoniker),
new DotNetCliBuilder(TargetFrameworkMoniker),
new ClassicExecutor())
{
}
Expand Down Expand Up @@ -57,8 +59,6 @@ public override bool IsSupported(Benchmark benchmark, ILogger logger)
return true;
}

private static string GetTargetFrameworkMoniker(Framework framework) => "netcoreapp1.0";

private static string GetExtraDependencies()
{
// do not set the type to platform in order to produce exe
Expand Down
8 changes: 4 additions & 4 deletions BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class DotNetCliBuilder : IBuilder

private static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(2);

private Func<Framework, string> TargetFrameworkMonikerProvider { get; }
private string TargetFrameworkMoniker { get; }

public DotNetCliBuilder(Func<Framework, string> targetFrameworkMonikerProvider)
public DotNetCliBuilder(string targetFrameworkMoniker)
{
TargetFrameworkMonikerProvider = targetFrameworkMonikerProvider;
TargetFrameworkMoniker = targetFrameworkMoniker;
}

/// <summary>
Expand All @@ -40,7 +40,7 @@ public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmar
}

if (!DotNetCliCommandExecutor.ExecuteCommand(
GetBuildCommand(TargetFrameworkMonikerProvider(benchmark.Job.Framework)),
GetBuildCommand(TargetFrameworkMoniker),
generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
logger,
DefaultTimeout))
Expand Down
10 changes: 5 additions & 5 deletions BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace BenchmarkDotNet.Toolchains.DotNetCli
{
internal class DotNetCliGenerator : GeneratorBase
{
private Func<Framework, string> TargetFrameworkMonikerProvider { get; }
private string TargetFrameworkMoniker { get; }

private string ExtraDependencies { get; }

Expand All @@ -22,13 +22,13 @@ internal class DotNetCliGenerator : GeneratorBase
private string Runtime { get; }

public DotNetCliGenerator(
Func<Framework, string> targetFrameworkMonikerProvider,
string targetFrameworkMoniker,
string extraDependencies,
Func<Platform, string> platformProvider,
string imports,
string runtime = null)
{
TargetFrameworkMonikerProvider = targetFrameworkMonikerProvider;
TargetFrameworkMoniker = targetFrameworkMoniker;
ExtraDependencies = extraDependencies;
PlatformProvider = platformProvider;
Imports = imports;
Expand Down Expand Up @@ -108,7 +108,7 @@ protected override void GenerateProject(Benchmark benchmark, ArtifactsPaths arti
var content = SetPlatform(template, PlatformProvider(benchmark.Job.Platform));
content = SetCodeFileName(content, Path.GetFileName(artifactsPaths.ProgramCodePath));
content = SetDependencyToExecutingAssembly(content, benchmark.Target.Type);
content = SetTargetFrameworkMoniker(content, TargetFrameworkMonikerProvider(benchmark.Job.Framework));
content = SetTargetFrameworkMoniker(content, TargetFrameworkMoniker);
content = SetExtraDependencies(content, ExtraDependencies);
content = SetImports(content, Imports);
content = SetRuntime(content, Runtime);
Expand All @@ -120,7 +120,7 @@ protected override void GenerateProject(Benchmark benchmark, ArtifactsPaths arti
protected override void GenerateBuildScript(Benchmark benchmark, ArtifactsPaths artifactsPaths)
{
var content = $"call dotnet {DotNetCliBuilder.RestoreCommand}{Environment.NewLine}" +
$"call dotnet {DotNetCliBuilder.GetBuildCommand(TargetFrameworkMonikerProvider(benchmark.Job.Framework))}";
$"call dotnet {DotNetCliBuilder.GetBuildCommand(TargetFrameworkMoniker)}";

File.WriteAllText(artifactsPaths.BuildScriptFilePath, content);
}
Expand Down

0 comments on commit 9761182

Please sign in to comment.