Skip to content

Commit c2bde2d

Browse files
committed
Merge branch 'master' into async-refactor
# Conflicts: # src/BenchmarkDotNet/BenchmarkDotNet.csproj # src/BenchmarkDotNet/Code/CodeGenerator.cs # src/BenchmarkDotNet/Code/DeclarationsProvider.cs # src/BenchmarkDotNet/Templates/BenchmarkProgram.txt
2 parents 2244617 + 2d71583 commit c2bde2d

81 files changed

Lines changed: 1541 additions & 638 deletions

File tree

Some content is hidden

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

.github/workflows/run-tests.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ jobs:
1818
os: [windows-latest, windows-11-arm]
1919
runs-on: ${{ matrix.os }}
2020
steps:
21-
- name: Disable Windows Defender
22-
run: Set-MpPreference -DisableRealtimeMonitoring $true
21+
- name: Add Windows Defender Exclusions
2322
shell: powershell
23+
run: |
24+
Add-MpPreference -ExclusionPath $env:GITHUB_WORKSPACE
25+
Add-MpPreference -ExclusionPath $env:TEMP
2426
- uses: actions/checkout@v6
2527
# Build and Test
2628
- name: Run task 'build'
@@ -51,9 +53,11 @@ jobs:
5153
os: [windows-latest, windows-11-arm]
5254
runs-on: ${{ matrix.os }}
5355
steps:
54-
- name: Disable Windows Defender
55-
run: Set-MpPreference -DisableRealtimeMonitoring $true
56+
- name: Add Windows Defender Exclusions
5657
shell: powershell
58+
run: |
59+
Add-MpPreference -ExclusionPath $env:GITHUB_WORKSPACE
60+
Add-MpPreference -ExclusionPath $env:TEMP
5761
- uses: actions/checkout@v6
5862
# Build and Test
5963
- name: Run task 'build'

docs/articles/overview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ namespace MyBenchmarks
5757
}
5858
```
5959

60-
The `BenchmarkRunner.Run<Md5VsSha256>()` call runs your benchmarks and prints results to the console.
60+
The `BenchmarkRunner.Run(typeof(Program).Assembly)` call runs all benchmarks in the current assembly and prints results to the console. If you'd like to run a single benchmark type, you can use `BenchmarkRunner.Run<Md5VsSha256>()`.
61+
62+
BenchmarkDotNet discovers benchmark types via reflection, so benchmarks can be placed in different files as long as they are in the same project/assembly and the benchmark classes are `public`.
6163

6264
Note that BenchmarkDotNet will only run benchmarks if the application is built in the Release configuration.
6365
This is to prevent unoptimized code from being benchmarked.

src/BenchmarkDotNet.Annotations/Jobs/RuntimeMoniker.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,25 @@ public enum RuntimeMoniker
248248
/// .NET 11 using MonoVM (not CLR which is the default)
249249
/// </summary>
250250
Mono11_0,
251+
252+
/// <summary>
253+
/// .NET 8 CLR with composite ReadyToRun compilation
254+
/// </summary>
255+
R2R80,
256+
257+
/// <summary>
258+
/// .NET 9 CLR with composite ReadyToRun compilation
259+
/// </summary>
260+
R2R90,
261+
262+
/// <summary>
263+
/// .NET 10 CLR with composite ReadyToRun compilation
264+
/// </summary>
265+
R2R10_0,
266+
267+
/// <summary>
268+
/// .NET 11 CLR with composite ReadyToRun compilation
269+
/// </summary>
270+
R2R11_0,
251271
}
252272
}

src/BenchmarkDotNet.Diagnostics.dotMemory/DotMemoryDiagnoser.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DotMemoryDiagnoser(Uri? nugetUrl = null, string? downloadTo = null)
1414

1515
protected override void InitTool(Progress progress)
1616
{
17-
DotMemory.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).Wait();
17+
DotMemory.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).GetAwaiter().GetResult();
1818
}
1919

2020
protected override void AttachToCurrentProcess(string snapshotFile)
@@ -24,7 +24,11 @@ protected override void AttachToCurrentProcess(string snapshotFile)
2424

2525
protected override void AttachToProcessByPid(int pid, string snapshotFile)
2626
{
27-
DotMemory.Attach(new DotMemory.Config().ProfileExternalProcess(pid).SaveToFile(snapshotFile));
27+
var config = new DotMemory.Config()
28+
.UseCustomResponseTimeout(milliseconds:60 * 1000)
29+
.ProfileExternalProcess(pid)
30+
.SaveToFile(snapshotFile);
31+
DotMemory.Attach(config);
2832
}
2933

3034
protected override void TakeSnapshot()
@@ -83,6 +87,10 @@ internal override bool IsSupported(RuntimeMoniker runtimeMoniker)
8387
case RuntimeMoniker.Net90:
8488
case RuntimeMoniker.Net10_0:
8589
case RuntimeMoniker.Net11_0:
90+
case RuntimeMoniker.R2R80:
91+
case RuntimeMoniker.R2R90:
92+
case RuntimeMoniker.R2R10_0:
93+
case RuntimeMoniker.R2R11_0:
8694
return true;
8795
case RuntimeMoniker.NotRecognized:
8896
case RuntimeMoniker.Mono:

src/BenchmarkDotNet.Diagnostics.dotTrace/DotTraceDiagnoser.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DotTraceDiagnoser(Uri? nugetUrl = null, string? downloadTo = null)
1414

1515
protected override void InitTool(Progress progress)
1616
{
17-
DotTrace.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).Wait();
17+
DotTrace.InitAsync(progress, nugetUrl, NuGetApi.V3, downloadTo).GetAwaiter().GetResult();
1818
}
1919

2020
protected override void AttachToCurrentProcess(string snapshotFile)
@@ -25,7 +25,11 @@ protected override void AttachToCurrentProcess(string snapshotFile)
2525

2626
protected override void AttachToProcessByPid(int pid, string snapshotFile)
2727
{
28-
DotTrace.Attach(new DotTrace.Config().ProfileExternalProcess(pid).SaveToFile(snapshotFile));
28+
var config = new DotTrace.Config()
29+
.UseCustomResponseTimeout(milliseconds: 60 * 1000)
30+
.ProfileExternalProcess(pid)
31+
.SaveToFile(snapshotFile);
32+
DotTrace.Attach(config);
2933
DotTrace.StartCollectingData();
3034
}
3135

@@ -86,6 +90,10 @@ internal override bool IsSupported(RuntimeMoniker runtimeMoniker)
8690
case RuntimeMoniker.Net90:
8791
case RuntimeMoniker.Net10_0:
8892
case RuntimeMoniker.Net11_0:
93+
case RuntimeMoniker.R2R80:
94+
case RuntimeMoniker.R2R90:
95+
case RuntimeMoniker.R2R10_0:
96+
case RuntimeMoniker.R2R11_0:
8997
return true;
9098
case RuntimeMoniker.NotRecognized:
9199
case RuntimeMoniker.Mono:
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using System;
22
using BenchmarkDotNet.Configs;
33

4+
#nullable enable
5+
46
namespace BenchmarkDotNet.Attributes
57
{
68
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly)]
79
public class ConfigAttribute : Attribute, IConfigSource
810
{
911
public IConfig Config { get; }
1012

11-
public ConfigAttribute(Type type) => Config = (IConfig)Activator.CreateInstance(type);
13+
public ConfigAttribute(Type type) => Config = (IConfig)Activator.CreateInstance(type)!;
1214
}
1315
}

src/BenchmarkDotNet/Attributes/Jobs/SimpleJobAttribute.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using BenchmarkDotNet.Jobs;
66
using JetBrains.Annotations;
77

8+
#nullable enable
9+
810
namespace BenchmarkDotNet.Attributes
911
{
1012
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
@@ -18,7 +20,7 @@ public SimpleJobAttribute(
1820
int warmupCount = DefaultValue,
1921
int iterationCount = DefaultValue,
2022
int invocationCount = DefaultValue,
21-
string? id = null,
23+
string id = "",
2224
bool baseline = false
2325
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, null, baseline)) { }
2426

@@ -29,7 +31,7 @@ public SimpleJobAttribute(
2931
int warmupCount = DefaultValue,
3032
int iterationCount = DefaultValue,
3133
int invocationCount = DefaultValue,
32-
string? id = null,
34+
string id = "",
3335
bool baseline = false
3436
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, runStrategy, baseline)) { }
3537

@@ -40,7 +42,7 @@ public SimpleJobAttribute(
4042
int warmupCount = DefaultValue,
4143
int iterationCount = DefaultValue,
4244
int invocationCount = DefaultValue,
43-
string? id = null,
45+
string id = "",
4446
bool baseline = false
4547
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, null, baseline, runtimeMoniker)) { }
4648

@@ -52,11 +54,11 @@ public SimpleJobAttribute(
5254
int warmupCount = DefaultValue,
5355
int iterationCount = DefaultValue,
5456
int invocationCount = DefaultValue,
55-
string? id = null,
57+
string id = "",
5658
bool baseline = false
5759
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, runStrategy, baseline, runtimeMoniker)) { }
5860

59-
private static Job CreateJob(string? id, int launchCount, int warmupCount, int iterationCount, int invocationCount, RunStrategy? runStrategy,
61+
private static Job CreateJob(string id, int launchCount, int warmupCount, int iterationCount, int invocationCount, RunStrategy? runStrategy,
6062
bool baseline, RuntimeMoniker runtimeMoniker = RuntimeMoniker.HostProcess)
6163
{
6264
var job = new Job(id);

src/BenchmarkDotNet/BenchmarkDotNet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
3030
<PackageReference Include="System.Management" Version="10.0.1" />
3131
<PackageReference Include="System.Linq.AsyncEnumerable" Version="10.0.1" />
32+
<PackageReference Include="System.Text.Json" Version="10.0.1" />
3233
</ItemGroup>
3334
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
3435
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />

src/BenchmarkDotNet/Characteristics/CharacteristicPresenter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public override string ToPresentation(object? value, Characteristic characterist
4040
if (characteristic == EnvironmentMode.AffinityCharacteristic && value is IntPtr intPtr)
4141
return intPtr.ToPresentation(Environment.ProcessorCount);
4242

43+
if (characteristic == EnvironmentMode.PowerPlanModeCharacteristic && value is Guid guid && guid == Guid.Empty)
44+
return ""; // Replace Guid.Empty to empty string.
45+
4346
return ToPresentation(value);
4447
}
4548

@@ -70,8 +73,6 @@ private static string ToPresentation(object? value)
7073
=> (value as IFormattable)?.ToString(null, DefaultCultureInfo.Instance)
7174
?? value?.ToString()
7275
?? "";
73-
74-
7576
}
7677

7778
private class SourceCodeCharacteristicPresenter : CharacteristicPresenter

src/BenchmarkDotNet/Characteristics/CharacteristicSetPresenter.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using BenchmarkDotNet.Diagnosers;
1+
using BenchmarkDotNet.Diagnosers;
52
using BenchmarkDotNet.Environments;
63
using BenchmarkDotNet.Jobs;
74
using BenchmarkDotNet.Toolchains;
85
using JetBrains.Annotations;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
10+
#nullable enable
911

1012
namespace BenchmarkDotNet.Characteristics
1113
{
@@ -58,7 +60,9 @@ private class DisplayPresenter : CharacteristicSetPresenter
5860
public override string ToPresentation(CharacteristicObject obj)
5961
{
6062
var values = GetPresentableCharacteristics(obj)
61-
.Select(c => c.Id + "=" + CharacteristicPresenter.ToPresentation(obj, c));
63+
.Select(c => (c.Id, Value: CharacteristicPresenter.ToPresentation(obj, c)))
64+
.Where(x => x.Value != "")
65+
.Select(x => $"{x.Id}={x.Value}");
6266
return string.Join(Separator, values);
6367
}
6468
}

0 commit comments

Comments
 (0)