Skip to content

Commit 72602a1

Browse files
committed
Merge branch 'master' into reduce-async-overhead
# Conflicts: # src/BenchmarkDotNet/Templates/BenchmarkType.txt
2 parents 8a8520f + 41a1517 commit 72602a1

File tree

84 files changed

+1094
-846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1094
-846
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ It's [easy](#Simplicity) to start writing benchmarks, check out an example
3737
```cs
3838
[SimpleJob(RuntimeMoniker.Net472, baseline: true)]
3939
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
40-
[SimpleJob(RuntimeMoniker.CoreRt30)]
40+
[SimpleJob(RuntimeMoniker.NativeAot70)]
4141
[SimpleJob(RuntimeMoniker.Mono)]
4242
[RPlotExporter]
4343
public class Md5VsSha256
@@ -75,30 +75,30 @@ Intel Core i7-7700K CPU 4.20GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cor
7575
[Host] : .NET Framework 4.7.2 (4.7.3468.0), X64 RyuJIT
7676
Net472 : .NET Framework 4.7.2 (4.7.3468.0), X64 RyuJIT
7777
NetCoreApp30 : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), X64 RyuJIT
78-
CoreRt30 : .NET CoreRT 1.0.28231.02 @Commit: 741d61493c560ba96e8151f9e56876d4d3828489, X64 AOT
78+
NativeAot70 : .NET 7.0.0-preview.4.22172.7, X64 NativeAOT
7979
Mono : Mono 6.4.0 (Visual Studio), X64
8080

8181

8282
| Method | Runtime | N | Mean | Error | StdDev | Ratio |
8383
|------- |-------------- |------ |-----------:|----------:|----------:|------:|
8484
| Sha256 | .NET 4.7.2 | 1000 | 7.735 us | 0.1913 us | 0.4034 us | 1.00 |
8585
| Sha256 | .NET Core 3.0 | 1000 | 3.989 us | 0.0796 us | 0.0745 us | 0.50 |
86-
| Sha256 | CoreRt 3.0 | 1000 | 4.091 us | 0.0811 us | 0.1562 us | 0.53 |
86+
| Sha256 | NativeAOT 7.0 | 1000 | 4.091 us | 0.0811 us | 0.1562 us | 0.53 |
8787
| Sha256 | Mono | 1000 | 13.117 us | 0.2485 us | 0.5019 us | 1.70 |
8888
| | | | | | | |
8989
| Md5 | .NET 4.7.2 | 1000 | 2.872 us | 0.0552 us | 0.0737 us | 1.00 |
9090
| Md5 | .NET Core 3.0 | 1000 | 1.848 us | 0.0348 us | 0.0326 us | 0.64 |
91-
| Md5 | CoreRt 3.0 | 1000 | 1.817 us | 0.0359 us | 0.0427 us | 0.63 |
91+
| Md5 | NativeAOT 7.0 | 1000 | 1.817 us | 0.0359 us | 0.0427 us | 0.63 |
9292
| Md5 | Mono | 1000 | 3.574 us | 0.0678 us | 0.0753 us | 1.24 |
9393
| | | | | | | |
9494
| Sha256 | .NET 4.7.2 | 10000 | 74.509 us | 1.5787 us | 4.6052 us | 1.00 |
9595
| Sha256 | .NET Core 3.0 | 10000 | 36.049 us | 0.7151 us | 1.0025 us | 0.49 |
96-
| Sha256 | CoreRt 3.0 | 10000 | 36.253 us | 0.7076 us | 0.7571 us | 0.49 |
96+
| Sha256 | NativeAOT 7.0 | 10000 | 36.253 us | 0.7076 us | 0.7571 us | 0.49 |
9797
| Sha256 | Mono | 10000 | 116.350 us | 2.2555 us | 3.0110 us | 1.58 |
9898
| | | | | | | |
9999
| Md5 | .NET 4.7.2 | 10000 | 17.308 us | 0.3361 us | 0.4250 us | 1.00 |
100100
| Md5 | .NET Core 3.0 | 10000 | 15.726 us | 0.2064 us | 0.1930 us | 0.90 |
101-
| Md5 | CoreRt 3.0 | 10000 | 15.627 us | 0.2631 us | 0.2461 us | 0.89 |
101+
| Md5 | NativeAOT 7.0 | 10000 | 15.627 us | 0.2631 us | 0.2461 us | 0.89 |
102102
| Md5 | Mono | 10000 | 30.205 us | 0.5868 us | 0.6522 us | 1.74 |
103103

104104
```
@@ -107,7 +107,7 @@ The measured data can be exported to different formats (md, html, csv, xml, json
107107

108108
![](docs/images/v0.12.0/rplot.png)
109109

110-
*Supported runtimes:* .NET 5+, .NET Framework 4.6.1+, .NET Core 2.0+, Mono, CoreRT
110+
*Supported runtimes:* .NET 5+, .NET Framework 4.6.1+, .NET Core 2.0+, Mono, NativeAOT
111111
*Supported languages:* C#, F#, Visual Basic
112112
*Supported OS:* Windows, Linux, macOS
113113
*Supported architectures:* x86, x64, ARM, ARM64 and Wasm

docs/articles/configs/toolchains.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To achieve process-level isolation, BenchmarkDotNet generates, builds and execut
1010
When you run your benchmarks without specifying the toolchain in an explicit way, the default one is used:
1111

1212
* Roslyn for Full .NET Framework and Mono
13-
* dotnet cli for .NET Core and CoreRT
13+
* dotnet cli for .NET Core and NativeAOT
1414

1515
## Multiple frameworks support
1616

@@ -188,28 +188,28 @@ Example: `dotnet run -c Release -- --coreRun "C:\Projects\corefx\bin\testhost\ne
188188
[!include[IntroInProcessWrongEnv](../samples/IntroInProcessWrongEnv.md)]
189189

190190

191-
## CoreRT
191+
## NativeAOT
192192

193-
BenchmarkDotNet supports [CoreRT](https://github.com/dotnet/runtimelab/tree/feature/NativeAOT)! However, you might want to know how it works to get a better understanding of the results that you get.
193+
BenchmarkDotNet supports [NativeAOT](https://github.com/dotnet/runtime/tree/main/src/coreclr/nativeaot/docs)! However, you might want to know how it works to get a better understanding of the results that you get.
194194

195-
* CoreRT is a flavor of .NET Core. Which means that:
196-
* you have to target .NET Core to be able to build CoreRT benchmarks (example: `<TargetFramework>net5.0</TargetFramework>` in the .csproj file)
197-
* you have to specify the CoreRT runtime in an explicit way, either by using `[SimpleJob]` attribute or by using the fluent Job config API `Job.ShortRun.With(CoreRtRuntime.$version)` or console line arguments `--runtimes corert50`
198-
* to run CoreRT benchmark you run the app as a .NET Core/.NET process (example: `dotnet run -c Release -f net5.01`) and BenchmarkDotNet does all the CoreRT compilation for you. If you want to check what files are generated you need to apply `[KeepBenchmarkFiles]` attribute to the class which defines benchmarks.
195+
* NativeAOT is a flavor of .NET Core. Which means that:
196+
* you have to target .NET Core to be able to build NativeAOT benchmarks (example: `<TargetFramework>net7.0</TargetFramework>` in the .csproj file)
197+
* you have to specify the NativeAOT runtime in an explicit way, either by using `[SimpleJob]` attribute or by using the fluent Job config API `Job.ShortRun.With(NativeAotRuntime.$version)` or console line arguments `--runtimes nativeaot7.0`
198+
* to run NativeAOT benchmark you run the app as a .NET Core/.NET process (example: `dotnet run -c Release -f net5.01`) and BenchmarkDotNet does all the NativeAOT compilation for you. If you want to check what files are generated you need to apply `[KeepBenchmarkFiles]` attribute to the class which defines benchmarks.
199199

200-
By default BenchmarkDotNet uses the latest version of `Microsoft.DotNet.ILCompiler` to build the CoreRT benchmark according to [this instructions](https://github.com/dotnet/runtimelab/blob/d0a37893a67c125f9b0cd8671846ff7d867df241/samples/HelloWorld/README.md#add-corert-to-your-project).
200+
By default BenchmarkDotNet uses the latest version of `Microsoft.DotNet.ILCompiler` to build the NativeAOT benchmark according to [this instructions](https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md).
201201

202202
```cs
203203
var config = DefaultConfig.Instance
204-
.With(Job.Default.With(CoreRtRuntime.CoreRt50)); // compiles the benchmarks as net5.0 and uses the latest CoreRT to build a native app
204+
.With(Job.Default.With(NativeAotRuntime.Net70)); // compiles the benchmarks as net7.0 and uses the latest NativeAOT to build a native app
205205
206206
BenchmarkSwitcher
207207
.FromAssembly(typeof(Program).Assembly)
208208
.Run(args, config);
209209
```
210210

211211
```cs
212-
[SimpleJob(RuntimeMoniker.CoreRt50)] // compiles the benchmarks as net5.0 and uses the latest CoreRT to build a native app
212+
[SimpleJob(RuntimeMoniker.NativeAot70)] // compiles the benchmarks as net7.0 and uses the latest NativeAOT to build a native app
213213
public class TheTypeWithBenchmarks
214214
{
215215
[Benchmark] // the benchmarks go here
@@ -218,31 +218,31 @@ public class TheTypeWithBenchmarks
218218

219219
**Note**: BenchmarkDotNet is going to run `dotnet restore` on the auto-generated project. The first time it does so, it's going to take a **LOT** of time to download all the dependencies (few minutes). Just give it some time and don't press `Ctrl+C` too fast ;)
220220

221-
If you want to benchmark some particular version of CoreRT (or from a different NuGet feed) you have to specify it in an explicit way:
221+
If you want to benchmark some particular version of NativeAOT (or from a different NuGet feed) you have to specify it in an explicit way:
222222

223223
```cs
224224
var config = DefaultConfig.Instance
225225
.With(Job.ShortRun
226-
.With(CoreRtToolchain.CreateBuilder()
227-
.UseCoreRtNuGet(
228-
microsoftDotNetILCompilerVersion: "6.0.0-*", // the version goes here
229-
nuGetFeedUrl: "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json") // this address might change over time
230-
.DisplayName("CoreRT NuGet")
226+
.With(NativeAotToolchain.CreateBuilder()
227+
.UseNuGet(
228+
microsoftDotNetILCompilerVersion: "7.0.0-*", // the version goes here
229+
nuGetFeedUrl: "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json") // this address might change over time
230+
.DisplayName("NativeAOT NuGet")
231231
.TargetFrameworkMoniker("net5.0")
232232
.ToToolchain()));
233233
```
234234

235235
### Compiling source to native code using the ILCompiler you built
236236

237-
If you are an CoreRT contributor and you want to benchmark your local build of CoreRT you have to provide necessary info (IlcPath):
237+
If you are a NativeAOT contributor and you want to benchmark your local build of NativeAOT you have to provide necessary info (IlcPath):
238238

239239
```cs
240240
var config = DefaultConfig.Instance
241241
.With(Job.ShortRun
242-
.With(CoreRtToolchain.CreateBuilder()
243-
.UseCoreRtLocal(@"C:\Projects\corert\bin\Windows_NT.x64.Release") // IlcPath
244-
.DisplayName("Core RT RyuJit")
245-
.TargetFrameworkMoniker("netcoreapp2.1")
242+
.With(NativeAotToolchain.CreateBuilder()
243+
.UseLocalBuild(@"C:\Projects\corert\bin\Windows_NT.x64.Release") // IlcPath
244+
.DisplayName("NativeAOT local build")
245+
.TargetFrameworkMoniker("net7.0")
246246
.ToToolchain()));
247247
```
248248

@@ -258,15 +258,15 @@ If you want to test [CPP Code Generator](https://github.com/dotnet/corert/blob/7
258258
var config = DefaultConfig.Instance
259259
.With(Job.Default
260260
.With(
261-
CoreRtToolchain.CreateBuilder()
262-
.UseCoreRtLocal(@"C:\Projects\corert\bin\Windows_NT.x64.Release") // IlcPath
261+
NativeAotToolchain.CreateBuilder()
262+
.UseLocalBuild(@"C:\Projects\corert\bin\Windows_NT.x64.Release") // IlcPath
263263
.UseCppCodeGenerator() // ENABLE IT
264-
.TargetFrameworkMoniker("netcoreapp2.1")
264+
.TargetFrameworkMoniker("net7.0")
265265
.DisplayName("CPP")
266266
.ToToolchain()));
267267
```
268268

269-
**Note**: You might get some `The method or operation is not implemented.` errors as of today if the code that you are trying to benchmark is using some features that are not implemented by CoreRT/transpiler yet...
269+
**Note**: You might get some `The method or operation is not implemented.` errors as of today if the code that you are trying to benchmark is using some features that are not implemented by NativeAOT/transpiler yet...
270270

271271
## Wasm
272272

docs/articles/guides/console-args.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ You can also filter the benchmarks by categories:
110110

111111
The `--runtimes` or just `-r` allows you to run the benchmarks for selected Runtimes. Available options are:
112112

113-
* Clr - BDN will either use Roslyn (if you run it as .NET app) or latest installed .NET SDK to build the benchmarks (if you run it as .NET Core app)
114-
* Core - if you run it as .NET Core app, BDN will use the same target framework moniker, if you run it as .NET app it's going to use netcoreapp2.1
115-
* Mono - it's going to use the Mono from `$Path`, you can override it with `--monoPath`
116-
* CoreRT - it's going to use latest CoreRT. Can be customized with additional options: `--ilcPath`, `--coreRtVersion`
117-
* net46, net461, net462, net47, net471, net472 - to build and run benchmarks against specific .NET framework version
118-
* netcoreapp2.0, netcoreapp2.1, netcoreapp2.2, netcoreapp3.0 - to build and run benchmarks against specific .NET Core version
113+
* Clr - BDN will either use Roslyn (if you run it as .NET app) or latest installed .NET SDK to build the benchmarks (if you run it as .NET Core app).
114+
* Core - if you run it as .NET Core app, BDN will use the same target framework moniker, if you run it as .NET app it's going to use netcoreapp2.1.
115+
* Mono - it's going to use the Mono from `$Path`, you can override it with `--monoPath`.
116+
* net46, net461, net462, net47, net471, net472 - to build and run benchmarks against specific .NET framework version.
117+
* netcoreapp2.0, netcoreapp2.1, netcoreapp2.2, netcoreapp3.0, netcoreapp3.1, net5.0, net6.0, net7.0 - to build and run benchmarks against specific .NET Core version.
118+
* nativeaot5.0, nativeaot6.0, nativeaot7.0 - to build and run benchmarks using NativeAOT. Can be customized with additional options: `--ilcPath`, `--ilCompilerVersion`.
119119

120120
Example: run the benchmarks for .NET 4.7.2 and .NET Core 2.1:
121121

@@ -207,7 +207,7 @@ dotnet run -c Release -- --filter * --runtimes netcoreapp2.0 netcoreapp2.1 --sta
207207
* `--cli` path to dotnet cli (optional).
208208
* `--packages` the directory to restore packages to (optional).
209209
* `--coreRun` path(s) to CoreRun (optional).
210-
* `--coreRt` path to ILCompiler for CoreRT
210+
* `--ilcPath` path to ILCompiler for NativeAOT.
211211
* `--info` prints environment configuration including BenchmarkDotNet, OS, CPU and .NET version
212212
* `--stopOnFirstError` stop on first error.
213213
* `--help` display this help screen.

docs/articles/guides/troubleshooting.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## BenchmarkDotNet
44

5-
You need to be aware of the fact that to ensure process-level isolation BenchmarkDotNet generates, builds and executes every benchmark in a dedicated process. For .NET and Mono we generate a C# file and compile it using Roslyn. For .NET Core and CoreRT we generate not only C# file but also a project file which later is restored and build with dotnet cli. If your project has some non-trivial build settings like a `.props` and `.target` files or native dependencies things might not work well out of the box.
5+
You need to be aware of the fact that to ensure process-level isolation BenchmarkDotNet generates, builds and executes every benchmark in a dedicated process. For .NET and Mono we generate a C# file and compile it using Roslyn. For .NET Core and NativeAOT we generate not only C# file but also a project file which later is restored and build with dotnet cli. If your project has some non-trivial build settings like a `.props` and `.target` files or native dependencies things might not work well out of the box.
66

77
How do you know that BenchmarkDotNet has failed to build the project? BDN is going to tell you about it. An example:
88

@@ -31,7 +31,7 @@ If the error message is not clear enough, you need to investigate it further.
3131

3232
How to troubleshoot the build process:
3333

34-
1. Run the benchmarks.
34+
1. Run the benchmarks with `--logBuildOutput` command line argument.
3535
2. Read the error message. If it does not contain the answer to your problem, please continue to the next step.
3636
3. Go to the build artifacts folder (path printed by BDN).
3737
4. The folder should contain:

docs/articles/overview.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: Overview
1010
Create new console application and install the [BenchmarkDotNet](https://www.nuget.org/packages/BenchmarkDotNet/) NuGet package. We support:
1111

1212
* *Projects:* classic and modern with PackageReferences
13-
* *Runtimes:* Full .NET Framework (4.6+), .NET Core (2.0+), Mono, CoreRT
13+
* *Runtimes:* Full .NET Framework (4.6+), .NET Core (2.0+), Mono, NativeAOT
1414
* *OS:* Windows, Linux, MacOS
1515
* *Languages:* C#, F#, VB
1616

@@ -82,10 +82,10 @@ Frequency=1948699 Hz, Resolution=513.1629 ns, Timer=TSC
8282

8383
## Jobs
8484

85-
You can check several environments at once. For example, you can compare performance of Full .NET Framework, .NET Core, Mono and CoreRT. Just add the `ClrJob`, `MonoJob`, `CoreJob`, `CoreRtJob` attributes before the class declaration (it requires a .NETCore project, installed CoreCLR and Mono):
85+
You can check several environments at once. For example, you can compare performance of Full .NET Framework, .NET Core, Mono and NativeAOT. Just add the `ClrJob`, `MonoJob`, `CoreJob`, attributes before the class declaration (it requires .NET SDK and Mono to be installed and added to $PATH):
8686

8787
```cs
88-
[ClrJob, MonoJob, CoreJob, CoreRtJob]
88+
[ClrJob, MonoJob, CoreJob]
8989
public class Md5VsSha256
9090
```
9191

docs/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ It's [easy](#simplicity) to start writing benchmarks, check out an example
3838
```cs
3939
[SimpleJob(RuntimeMoniker.Net472, baseline: true)]
4040
[SimpleJob(RuntimeMoniker.NetCoreApp30)]
41-
[SimpleJob(RuntimeMoniker.CoreRt30)]
41+
[SimpleJob(RuntimeMoniker.NativeAot70)]
4242
[SimpleJob(RuntimeMoniker.Mono)]
4343
[RPlotExporter]
4444
public class Md5VsSha256
@@ -108,7 +108,7 @@ The measured data can be exported to different formats (md, html, csv, xml, json
108108

109109
![](images/v0.12.0/rplot.png)
110110

111-
*Supported runtimes:* .NET 5+, .NET Framework 4.6.1+, .NET Core 2.0+, Mono, CoreRT
111+
*Supported runtimes:* .NET 5+, .NET Framework 4.6.1+, .NET Core 2.0+, Mono, NativeAOT
112112
*Supported languages:* C#, F#, Visual Basic
113113
*Supported OS:* Windows, Linux, macOS
114114
*Supported architectures:* x86, x64, ARM, ARM64 and Wasm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Diagnostics.CodeAnalysis
5+
{
6+
/// <summary>
7+
/// Specifies the types of members that are dynamically accessed.
8+
///
9+
/// This enumeration has a <see cref="FlagsAttribute"/> attribute that allows a
10+
/// bitwise combination of its member values.
11+
/// </summary>
12+
[Flags]
13+
internal enum DynamicallyAccessedMemberTypes
14+
{
15+
/// <summary>
16+
/// Specifies no members.
17+
/// </summary>
18+
None = 0,
19+
20+
/// <summary>
21+
/// Specifies the default, parameterless public constructor.
22+
/// </summary>
23+
PublicParameterlessConstructor = 0x0001,
24+
25+
/// <summary>
26+
/// Specifies all public constructors.
27+
/// </summary>
28+
PublicConstructors = 0x0002 | PublicParameterlessConstructor,
29+
30+
/// <summary>
31+
/// Specifies all non-public constructors.
32+
/// </summary>
33+
NonPublicConstructors = 0x0004,
34+
35+
/// <summary>
36+
/// Specifies all public methods.
37+
/// </summary>
38+
PublicMethods = 0x0008,
39+
40+
/// <summary>
41+
/// Specifies all non-public methods.
42+
/// </summary>
43+
NonPublicMethods = 0x0010,
44+
45+
/// <summary>
46+
/// Specifies all public fields.
47+
/// </summary>
48+
PublicFields = 0x0020,
49+
50+
/// <summary>
51+
/// Specifies all non-public fields.
52+
/// </summary>
53+
NonPublicFields = 0x0040,
54+
55+
/// <summary>
56+
/// Specifies all public nested types.
57+
/// </summary>
58+
PublicNestedTypes = 0x0080,
59+
60+
/// <summary>
61+
/// Specifies all non-public nested types.
62+
/// </summary>
63+
NonPublicNestedTypes = 0x0100,
64+
65+
/// <summary>
66+
/// Specifies all public properties.
67+
/// </summary>
68+
PublicProperties = 0x0200,
69+
70+
/// <summary>
71+
/// Specifies all non-public properties.
72+
/// </summary>
73+
NonPublicProperties = 0x0400,
74+
75+
/// <summary>
76+
/// Specifies all public events.
77+
/// </summary>
78+
PublicEvents = 0x0800,
79+
80+
/// <summary>
81+
/// Specifies all non-public events.
82+
/// </summary>
83+
NonPublicEvents = 0x1000,
84+
85+
/// <summary>
86+
/// Specifies all members.
87+
/// </summary>
88+
All = ~None
89+
}
90+
}

0 commit comments

Comments
 (0)