Skip to content

Commit c7ed714

Browse files
keegan-carusoKeegan Carusotimcassell
authored
Remove obsolete API usage in articles (#2667)
* 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]>
1 parent 25308bf commit c7ed714

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

docs/articles/configs/diagnosers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ private class Config : ManualConfig
5959
{
6060
public Config()
6161
{
62-
Add(MemoryDiagnoser.Default);
63-
Add(new InliningDiagnoser());
64-
Add(new EtwProfiler());
65-
Add(ThreadingDiagnoser.Default);
66-
Add(ExceptionDiagnoser.Default);
62+
AddDiagnoser(MemoryDiagnoser.Default);
63+
AddDiagnoser(new InliningDiagnoser());
64+
AddDiagnoser(new EtwProfiler());
65+
AddDiagnoser(ThreadingDiagnoser.Default);
66+
AddDiagnoser(ExceptionDiagnoser.Default);
6767
}
6868
}
6969
```

docs/articles/configs/jobs.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,20 @@ public class MyBenchmarks
9898
{
9999
public Config()
100100
{
101-
Add(
102-
new Job("MySuperJob", RunMode.Dry, EnvMode.RyuJitX64)
101+
AddJob(
102+
new Job("MySuperJob", RunMode.Dry, EnvironmentMode.RyuJitX64)
103103
{
104-
Env = { Runtime = Runtime.Core },
104+
Environment = { Runtime = CoreRuntime.Core90 },
105105
Run = { LaunchCount = 5, IterationTime = TimeInterval.Millisecond * 200 },
106-
Accuracy = { MaxStdErrRelative = 0.01 }
106+
Accuracy = { MaxRelativeError = 0.01 }
107107
});
108108

109109
// The same, using the .With() factory methods:
110-
Add(
110+
AddJob(
111111
Job.Dry
112112
.WithPlatform(Platform.X64)
113113
.WithJit(Jit.RyuJit)
114-
.WithRuntime(Runtime.Core)
114+
.WithRuntime(CoreRuntime.Core90)
115115
.WithLaunchCount(5)
116116
.WithIterationTime(TimeInterval.Millisecond * 200)
117117
.WithMaxRelativeError(0.01)
@@ -122,26 +122,26 @@ public class MyBenchmarks
122122
}
123123
```
124124

125-
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.
125+
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.
126126

127127
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.
128128

129129
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
130130

131131
```cs
132-
var newJob = Job.Dry.With(Platform.X64);
132+
var newJob = Job.Dry.WithPlatform(Platform.X64);
133133
```
134134

135135
or pass the frozen value as a constructor argument
136136

137137
```c#
138-
var newJob = new Job(Job.Dry) { Env = { Platform = Platform.X64 } };
138+
var newJob = new Job(Job.Dry) { Environment = { Platform = Platform.X64 } };
139139
```
140140

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

143143
```c#
144-
var newJob = new Job() { Env = { Platform = Platform.X64 } }.Apply(Job.Dry);
144+
var newJob = new Job() { Environment = { Platform = Platform.X64 } }.Apply(Job.Dry);
145145
```
146146

147147
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).
@@ -152,7 +152,9 @@ You can also add new jobs via attributes. Examples:
152152

153153
```cs
154154
[DryJob]
155-
[ClrJob, CoreJob, MonoJob]
155+
[MonoJob]
156+
[SimpleJob(RuntimeMoniker.Net90)]
157+
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
156158
[LegacyJitX86Job, LegacyJitX64Job, RyuJitX64Job]
157159
[SimpleJob(RunStrategy.ColdStart, launchCount: 1, warmupCount: 5, iterationCount: 5, id: "FastAndDirtyJob")]
158160
public class MyBenchmarkClass
@@ -212,7 +214,7 @@ public class MySuperJobAttribute : Attribute, IConfigSource
212214
{
213215
var job = new Job("MySuperJob", RunMode.Core);
214216
job.Env.Platform = Platform.X64;
215-
Config = ManualConfig.CreateEmpty().With(job);
217+
Config = ManualConfig.CreateEmpty().AddJob(job);
216218
}
217219

218220
public IConfig Config { get; }

docs/articles/configs/toolchains.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ namespace BenchmarkDotNet.Samples
8787
static void Main(string[] args)
8888
{
8989
var config = DefaultConfig.Instance
90-
.With(Job.Default.With(CoreRuntime.Core21))
91-
.With(Job.Default.With(CoreRuntime.Core30))
92-
.With(Job.Default.With(ClrRuntime.Net48))
93-
.With(Job.Default.With(MonoRuntime.Default));
90+
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80))
91+
.AddJob(Job.Default.WithRuntime(ClrRuntime.Net48))
92+
.AddJob(Job.Default.WithRuntime(MonoRuntime.Default));
9493

9594
BenchmarkSwitcher
9695
.FromAssembly(typeof(Program).Assembly)
@@ -130,8 +129,8 @@ It's possible to benchmark a private build of .NET Runtime. All you need to do i
130129
BenchmarkSwitcher
131130
.FromAssembly(typeof(Program).Assembly)
132131
.Run(args,
133-
DefaultConfig.Instance.With(
134-
Job.ShortRun.With(ClrRuntime.CreateForLocalFullNetFrameworkBuild(version: "4.0"))));
132+
DefaultConfig.Instance.AddJob(
133+
Job.ShortRun.WithRuntime(ClrRuntime.CreateForLocalFullNetFrameworkBuild(version: "4.0"))));
135134
```
136135

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

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

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

339338
```cs
340339
var config = DefaultConfig.Instance
341-
.With(Job.ShortRun
342-
.With(NativeAotToolchain.CreateBuilder()
340+
.AddJob(Job.ShortRun
341+
.WithToolchain(NativeAotToolchain.CreateBuilder()
343342
.UseLocalBuild(@"C:\Projects\runtime\artifacts\packages\Release\Shipping\")
344343
.DisplayName("NativeAOT local build")
345344
.TargetFrameworkMoniker("net7.0")

0 commit comments

Comments
 (0)