Skip to content

Commit

Permalink
Current values for JitVersion, Platform, and Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed May 6, 2015
1 parent ce7f58d commit 295cc26
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions BenchmarkDotNet/Attributes/TaskAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class TaskAttribute : Attribute
public TaskAttribute(
int runCount = 1,
BenchmarkMode mode = BenchmarkMode.SingleRun,
BenchmarkPlatform platform = BenchmarkPlatform.AnyCpu,
BenchmarkJitVersion jitVersion = BenchmarkJitVersion.LegacyJit,
BenchmarkPlatform platform = BenchmarkPlatform.CurrentPlatform,
BenchmarkJitVersion jitVersion = BenchmarkJitVersion.CurrentJit,
BenchmarkFramework framework = BenchmarkFramework.V40,
int warmupIterationCount = 5,
int targetIterationCount = 10
Expand Down
13 changes: 12 additions & 1 deletion BenchmarkDotNet/BenchmarkProjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ private static void SaveProjectFile(string projectDir, BenchmarkConfiguration co
private static void SaveAppConfigFile(string projectDir, BenchmarkConfiguration configuration)
{
string appConfigPath = Path.Combine(projectDir, "app.config");
File.WriteAllText(appConfigPath, GetAppConfig(configuration.JitVersion.ToConfig()));
var content = configuration.JitVersion == BenchmarkJitVersion.CurrentJit ? GetEmptyAppConfig() : GetAppConfig(configuration.JitVersion.ToConfig());
File.WriteAllText(appConfigPath, content);
}

private static string CreateProjectDirectory(Benchmark benchmark)
Expand Down Expand Up @@ -206,6 +207,16 @@ private static string GetAppConfig(string useLegacyJit)
return appConfigTemplate.Replace("$USELEGACYJIT$", useLegacyJit);
}


private static string GetEmptyAppConfig()
{
const string appConfigTemplate = @"<?xml version=""1.0""?>
<configuration>
</configuration>
";
return appConfigTemplate;
}

#endregion
}
}
2 changes: 1 addition & 1 deletion BenchmarkDotNet/BenchmarkRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public IEnumerable<BenchmarkReport> RunCompetition(List<Benchmark> benchmarks)
}
Logger.WriteLineHeader("// ***** Competition: Finish *****");
Logger.NewLine();
Logger.WriteLineInfo(EnvironmentHelper.GetFullEnvironmentInfo(false));
Logger.WriteLineInfo(EnvironmentHelper.GetFullEnvironmentInfo());
var reportStats = reports.Select(
r => new
{
Expand Down
7 changes: 2 additions & 5 deletions BenchmarkDotNet/EnvironmentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,13 @@ private static string GetJitFlag()
return "";
}

public static string GetFullEnvironmentInfo(bool includeClr = true)
public static string GetFullEnvironmentInfo()
{
var line1 = $"// BenchmarkDotNet=v{GetBenchmarkDotNetVersion()}";
var line2 = $"// OS={GetOsVersion()}";
var line3 = $"// Processor={GetProcessorName()}, ProcessorCount={GetProcessorCount()}";
var line4 = $"// CLR={GetClrVersion()}, Arch={GetArch()} {GetConfiguration()}{GetDebuggerFlag()}{GetJitFlag()}";
var lines = new List<string> { line1, line2, line3 };
if (includeClr)
lines.Add(line4);
return string.Join(Environment.NewLine, lines.ToArray());
return string.Join(Environment.NewLine, new[] { line1, line2, line3, line4 });
}

private static string GetBenchmarkDotNetVersion()
Expand Down
22 changes: 21 additions & 1 deletion BenchmarkDotNet/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Linq;
using System.Reflection;
using BenchmarkDotNet.Tasks;

namespace BenchmarkDotNet.Extensions
Expand All @@ -15,18 +17,36 @@ public static string ToConfig(this BenchmarkPlatform platform)
return "x86";
case BenchmarkPlatform.X64:
return "x64";
case BenchmarkPlatform.CurrentPlatform:
return IntPtr.Size == 4 ? "x86" : "x64";
default:
return "AnyCPU";
}
}

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

private static string DetectCurrentFramework()
{
var attribute = Assembly.GetExecutingAssembly().GetCustomAttributes(false).
OfType<Attribute>().FirstOrDefault(a => a.ToString() == @"System.Runtime.Versioning.TargetFrameworkAttribute");
if (attribute == null)
return "v3.5";
var frameworkName = attribute.GetType()
.GetProperty("FrameworkName", BindingFlags.Public | BindingFlags.Instance)
.GetValue(attribute, null)?.ToString();
if (frameworkName != null)
frameworkName = frameworkName.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).FirstOrDefault() ?? "";
return frameworkName;
}

public static string ToConfig(this BenchmarkJitVersion jitVersion)
{
return jitVersion == BenchmarkJitVersion.LegacyJit ? "1" : "0";
Expand Down
2 changes: 1 addition & 1 deletion BenchmarkDotNet/Tasks/BenchmarkFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public enum BenchmarkFramework
{
V35, V40, V45, V451, V452, V46
Current, V35, V40, V45, V451, V452, V46
}
}
2 changes: 1 addition & 1 deletion BenchmarkDotNet/Tasks/BenchmarkJitVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public enum BenchmarkJitVersion
{
LegacyJit, RyuJit
CurrentJit, LegacyJit, RyuJit
}
}
2 changes: 1 addition & 1 deletion BenchmarkDotNet/Tasks/BenchmarkPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public enum BenchmarkPlatform
{
AnyCpu, X86, X64
CurrentPlatform, AnyCpu, X86, X64
}
}

0 comments on commit 295cc26

Please sign in to comment.