Skip to content

Commit

Permalink
Remove obsolete API usage in articles (#2667)
Browse files Browse the repository at this point in the history
* Remove obsolete API usage in articles

* Apply suggestions from code review

Co-authored-by: Tim Cassell <[email protected]>

---------

Co-authored-by: Keegan Caruso <[email protected]>
Co-authored-by: Tim Cassell <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent 25308bf commit c7ed714
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
10 changes: 5 additions & 5 deletions docs/articles/configs/diagnosers.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ private class Config : ManualConfig
{
public Config()
{
Add(MemoryDiagnoser.Default);
Add(new InliningDiagnoser());
Add(new EtwProfiler());
Add(ThreadingDiagnoser.Default);
Add(ExceptionDiagnoser.Default);
AddDiagnoser(MemoryDiagnoser.Default);
AddDiagnoser(new InliningDiagnoser());
AddDiagnoser(new EtwProfiler());
AddDiagnoser(ThreadingDiagnoser.Default);
AddDiagnoser(ExceptionDiagnoser.Default);
}
}
```
Expand Down
26 changes: 14 additions & 12 deletions docs/articles/configs/jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ public class MyBenchmarks
{
public Config()
{
Add(
new Job("MySuperJob", RunMode.Dry, EnvMode.RyuJitX64)
AddJob(
new Job("MySuperJob", RunMode.Dry, EnvironmentMode.RyuJitX64)
{
Env = { Runtime = Runtime.Core },
Environment = { Runtime = CoreRuntime.Core90 },
Run = { LaunchCount = 5, IterationTime = TimeInterval.Millisecond * 200 },
Accuracy = { MaxStdErrRelative = 0.01 }
Accuracy = { MaxRelativeError = 0.01 }
});

// The same, using the .With() factory methods:
Add(
AddJob(
Job.Dry
.WithPlatform(Platform.X64)
.WithJit(Jit.RyuJit)
.WithRuntime(Runtime.Core)
.WithRuntime(CoreRuntime.Core90)
.WithLaunchCount(5)
.WithIterationTime(TimeInterval.Millisecond * 200)
.WithMaxRelativeError(0.01)
Expand All @@ -122,26 +122,26 @@ public class MyBenchmarks
}
```

Basically, it's a good idea to start with predefined values (e.g. `EnvMode.RyuJitX64` and `RunMode.Dry` passed as constructor args) and modify rest of the properties using property setters or with help of object initializer syntax.
Basically, it's a good idea to start with predefined values (e.g. `EnvironmentMode.RyuJitX64` and `RunMode.Dry` passed as constructor args) and modify rest of the properties using property setters or with help of object initializer syntax.

Note that the job cannot be modified after it's added into config. Trying to set a value on property of the frozen job will throw an `InvalidOperationException`. Use the `Job.Frozen` property to determine if the code properties can be altered.

If you do want to create a new job based on frozen one (all predefined job values are frozen) you can use the `.With()` extension method

```cs
var newJob = Job.Dry.With(Platform.X64);
var newJob = Job.Dry.WithPlatform(Platform.X64);
```

or pass the frozen value as a constructor argument

```c#
var newJob = new Job(Job.Dry) { Env = { Platform = Platform.X64 } };
var newJob = new Job(Job.Dry) { Environment = { Platform = Platform.X64 } };
```

or use the `.Apply()` method on unfrozen job

```c#
var newJob = new Job() { Env = { Platform = Platform.X64 } }.Apply(Job.Dry);
var newJob = new Job() { Environment = { Platform = Platform.X64 } }.Apply(Job.Dry);
```

in any case the Id property will not be transfered and you must pass it explicitly (using the .ctor id argument or the `.WithId()` extension method).
Expand All @@ -152,7 +152,9 @@ You can also add new jobs via attributes. Examples:

```cs
[DryJob]
[ClrJob, CoreJob, MonoJob]
[MonoJob]
[SimpleJob(RuntimeMoniker.Net90)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[LegacyJitX86Job, LegacyJitX64Job, RyuJitX64Job]
[SimpleJob(RunStrategy.ColdStart, launchCount: 1, warmupCount: 5, iterationCount: 5, id: "FastAndDirtyJob")]
public class MyBenchmarkClass
Expand Down Expand Up @@ -212,7 +214,7 @@ public class MySuperJobAttribute : Attribute, IConfigSource
{
var job = new Job("MySuperJob", RunMode.Core);
job.Env.Platform = Platform.X64;
Config = ManualConfig.CreateEmpty().With(job);
Config = ManualConfig.CreateEmpty().AddJob(job);
}

public IConfig Config { get; }
Expand Down
21 changes: 10 additions & 11 deletions docs/articles/configs/toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ namespace BenchmarkDotNet.Samples
static void Main(string[] args)
{
var config = DefaultConfig.Instance
.With(Job.Default.With(CoreRuntime.Core21))
.With(Job.Default.With(CoreRuntime.Core30))
.With(Job.Default.With(ClrRuntime.Net48))
.With(Job.Default.With(MonoRuntime.Default));
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80))
.AddJob(Job.Default.WithRuntime(ClrRuntime.Net48))
.AddJob(Job.Default.WithRuntime(MonoRuntime.Default));

BenchmarkSwitcher
.FromAssembly(typeof(Program).Assembly)
Expand Down Expand Up @@ -130,8 +129,8 @@ It's possible to benchmark a private build of .NET Runtime. All you need to do i
BenchmarkSwitcher
.FromAssembly(typeof(Program).Assembly)
.Run(args,
DefaultConfig.Instance.With(
Job.ShortRun.With(ClrRuntime.CreateForLocalFullNetFrameworkBuild(version: "4.0"))));
DefaultConfig.Instance.AddJob(
Job.ShortRun.WithRuntime(ClrRuntime.CreateForLocalFullNetFrameworkBuild(version: "4.0"))));
```

This sends the provided version as a `COMPLUS_Version` env var to the benchmarked process.
Expand Down Expand Up @@ -208,7 +207,7 @@ or:

```cs
var config = DefaultConfig.Instance
.With(Job.Default.With(NativeAotRuntime.Net70)); // compiles the benchmarks as net7.0 and uses the latest NativeAOT to build a native app
.AddJob(Job.Default.WithRuntime(NativeAotRuntime.Net70)); // compiles the benchmarks as net7.0 and uses the latest NativeAOT to build a native app
BenchmarkSwitcher
.FromAssembly(typeof(Program).Assembly)
Expand All @@ -231,8 +230,8 @@ If you want to benchmark some particular version of NativeAOT (or from a differe

```cs
var config = DefaultConfig.Instance
.With(Job.ShortRun
.With(NativeAotToolchain.CreateBuilder()
.AddJob(Job.ShortRun
.WithToolchain(NativeAotToolchain.CreateBuilder()
.UseNuGet(
microsoftDotNetILCompilerVersion: "7.0.0-*", // the version goes here
nuGetFeedUrl: "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json") // this address might change over time
Expand Down Expand Up @@ -338,8 +337,8 @@ or explicitly in the code:

```cs
var config = DefaultConfig.Instance
.With(Job.ShortRun
.With(NativeAotToolchain.CreateBuilder()
.AddJob(Job.ShortRun
.WithToolchain(NativeAotToolchain.CreateBuilder()
.UseLocalBuild(@"C:\Projects\runtime\artifacts\packages\Release\Shipping\")
.DisplayName("NativeAOT local build")
.TargetFrameworkMoniker("net7.0")
Expand Down

0 comments on commit c7ed714

Please sign in to comment.