You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
194
194
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.
199
199
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).
201
201
202
202
```cs
203
203
varconfig=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
205
205
206
206
BenchmarkSwitcher
207
207
.FromAssembly(typeof(Program).Assembly)
208
208
.Run(args, config);
209
209
```
210
210
211
211
```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
213
213
publicclassTheTypeWithBenchmarks
214
214
{
215
215
[Benchmark] // the benchmarks go here
@@ -218,31 +218,31 @@ public class TheTypeWithBenchmarks
218
218
219
219
**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 ;)
220
220
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:
222
222
223
223
```cs
224
224
varconfig=DefaultConfig.Instance
225
225
.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")
231
231
.TargetFrameworkMoniker("net5.0")
232
232
.ToToolchain()));
233
233
```
234
234
235
235
### Compiling source to native code using the ILCompiler you built
236
236
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):
**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...
Copy file name to clipboardExpand all lines: docs/articles/guides/console-args.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -110,12 +110,12 @@ You can also filter the benchmarks by categories:
110
110
111
111
The `--runtimes` or just `-r` allows you to run the benchmarks for selected Runtimes. Available options are:
112
112
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`.
119
119
120
120
Example: run the benchmarks for .NET 4.7.2 and .NET Core 2.1:
Copy file name to clipboardExpand all lines: docs/articles/guides/troubleshooting.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## BenchmarkDotNet
4
4
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.
6
6
7
7
How do you know that BenchmarkDotNet has failed to build the project? BDN is going to tell you about it. An example:
8
8
@@ -31,7 +31,7 @@ If the error message is not clear enough, you need to investigate it further.
31
31
32
32
How to troubleshoot the build process:
33
33
34
-
1. Run the benchmarks.
34
+
1. Run the benchmarks with `--logBuildOutput` command line argument.
35
35
2. Read the error message. If it does not contain the answer to your problem, please continue to the next step.
36
36
3. Go to the build artifacts folder (path printed by BDN).
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):
0 commit comments