SimpleJob attribute: how so specify RuntimeMoniker equivalent to net6.0-windows #2408
-
I want to benchmark classes in a WPF Class Library that multi-targets both .NET 6.0 and .NET Framework 4.8. Here's project file: WpfClassLibrary.cs: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-windows;net4.8</TargetFrameworks>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project> The class I want to test, simple instantiates a namespace WpfClassLibrary
{
using System.Windows.Documents;
public class WpfClass
{
public FlowDocument Document { get; } = new FlowDocument();
}
} Here's the project file for the benchmarking project: BenchmarkingWpfClassLibrary.csproj: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0-windows;net4.8</TargetFrameworks>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WpfClassLibrary\WpfClassLibrary.csproj" />
</ItemGroup>
</Project> And the benchmark itself: Program.cs: namespace Benchmarks
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using WpfClassLibrary;
internal class Program
{
static void Main(string[] args)
{
var results = BenchmarkRunner.Run<WpfClassBenchmarks>();
}
}
//[SimpleJob(RuntimeMoniker.Net48)]
//[SimpleJob(RuntimeMoniker.Net60)]
public class WpfClassBenchmarks
{
[Benchmark]
public void WpfClass()
{
_ = new WpfClass();
}
}
} If I run this as-is the benchmark builds and runs fine. However, if I comment out the two
I think what is happening is that when specifying no How can I specify a simple job that uses the runtime moniker of Source code: https://github.com/DanStevens/BenchmarkingWpfClassLibrary |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @DanStevens We don't provide API for that, the best I can do right now is to provide a workaround (see the explanation in comments): var net48 = Job.Default.WithRuntime(ClrRuntime.Net48).AsBaseline().WithId(".NET 4.8");
// It's impossible to specify "net6.0-windows" via the existing APIs.
// But if the process is run as net6.0, the default BDN Job will properly recognize and use "net6.0-windows" moniker.
var net60windows = Job.Default.WithId(".NET 6.0");
var config = DefaultConfig.Instance
.AddJob(net48)
.AddJob(net60windows);
BenchmarkRunner.Run<WpfClassBenchmarks>(config); dotnet run -c Release -f net6.0 |
Beta Was this translation helpful? Give feedback.
You could manually create the toolchain like this:
That doesn't rely on the host process.