Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions src/BenchmarkDotNet.Diagnostics.Windows/JitStatsDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override void AttachToEvents(TraceEventSession session, BenchmarkCase

private sealed class MethodsJittedDescriptor : IMetricDescriptor
{
internal static readonly MethodsJittedDescriptor Instance = new ();
internal static readonly MethodsJittedDescriptor Instance = new();

public string Id => nameof(MethodsJittedDescriptor);
public string DisplayName => "Methods JITted";
Expand All @@ -75,7 +75,7 @@ private sealed class MethodsJittedDescriptor : IMetricDescriptor

private sealed class MethodsTieredDescriptor : IMetricDescriptor
{
internal static readonly MethodsTieredDescriptor Instance = new ();
internal static readonly MethodsTieredDescriptor Instance = new();

public string Id => nameof(MethodsTieredDescriptor);
public string DisplayName => "Methods Tiered";
Expand All @@ -90,7 +90,7 @@ private sealed class MethodsTieredDescriptor : IMetricDescriptor

private sealed class JitAllocatedMemoryDescriptor : IMetricDescriptor
{
internal static readonly JitAllocatedMemoryDescriptor Instance = new ();
internal static readonly JitAllocatedMemoryDescriptor Instance = new();

public string Id => nameof(JitAllocatedMemoryDescriptor);
public string DisplayName => "JIT allocated memory";
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet.TestAdapter/BenchmarkExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace BenchmarkDotNet.TestAdapter
/// </summary>
internal class BenchmarkExecutor
{
private readonly CancellationTokenSource cts = new ();
private readonly CancellationTokenSource cts = new();

/// <summary>
/// Runs all the benchmarks in the given assembly, updating the TestExecutionRecorder as they get run.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BenchmarkDotNet.TestAdapter.Remoting
/// </summary>
internal class BenchmarkExecutorWrapper : MarshalByRefObject
{
private readonly BenchmarkExecutor benchmarkExecutor = new ();
private readonly BenchmarkExecutor benchmarkExecutor = new();

public void RunBenchmarks(string assemblyPath, TestExecutionRecorderWrapper recorder, HashSet<Guid>? benchmarkIds = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/BenchmarkDotNet.TestAdapter/VSTestEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ internal class VsTestEventProcessor : EventProcessor
private readonly Dictionary<Guid, TestCase> cases;
private readonly TestExecutionRecorderWrapper recorder;
private readonly CancellationToken cancellationToken;
private readonly Stopwatch runTimerStopwatch = new ();
private readonly Dictionary<Guid, TestResult> testResults = new ();
private readonly HashSet<Guid> sentTestResults = new ();
private readonly Stopwatch runTimerStopwatch = new();
private readonly Dictionary<Guid, TestResult> testResults = new();
private readonly HashSet<Guid> sentTestResults = new();

public VsTestEventProcessor(
List<TestCase> cases,
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Columns/StatisticalTestColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class StatisticalTestColumn(Threshold threshold, SignificanceLevel? signi
{
private static readonly SignificanceLevel DefaultSignificanceLevel = SignificanceLevel.P1E5;

public static StatisticalTestColumn CreateDefault() => new (new PercentValue(10).ToThreshold());
public static StatisticalTestColumn CreateDefault() => new(new PercentValue(10).ToThreshold());

public static StatisticalTestColumn Create(Threshold threshold, SignificanceLevel? significanceLevel = null) => new (threshold, significanceLevel);
public static StatisticalTestColumn Create(Threshold threshold, SignificanceLevel? significanceLevel = null) => new(threshold, significanceLevel);

public static StatisticalTestColumn Create(string threshold, SignificanceLevel? significanceLevel = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static (bool isSuccess, IConfig config, CommandLineOptions options) Parse

private static (bool Success, string[] ExpandedTokens) ExpandResponseFile(string[] args, ILogger logger)
{
List<string> result = new ();
List<string> result = new();
foreach (var arg in args)
{
if (arg.StartsWith("@"))
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Detectors/Cpu/HardwareIntrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static IEnumerable<string> GetCurrentProcessInstructionSets(Platform platform)

private static string GetShortAvx512Representation()
{
StringBuilder avx512 = new ("AVX-512F");
StringBuilder avx512 = new("AVX-512F");
if (IsX86Avx512CDSupported) avx512.Append("+CD");
if (IsX86Avx512BWSupported) avx512.Append("+BW");
if (IsX86Avx512DQSupported) avx512.Append("+DQ");
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Detectors/CpuDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace BenchmarkDotNet.Detectors;

public class CpuDetector(params ICpuDetector[] detectors) : ICpuDetector
{
public static CpuDetector CrossPlatform => new (
public static CpuDetector CrossPlatform => new(
new WindowsCpuDetector(),
new LinuxCpuDetector(),
new MacOsCpuDetector());

private static readonly Lazy<CpuInfo?> LazyCpu = new (() => CrossPlatform.Detect());
private static readonly Lazy<CpuInfo?> LazyCpu = new(() => CrossPlatform.Detect());
public static CpuInfo? Cpu => LazyCpu.Value;

public bool IsApplicable() => detectors.Any(loader => loader.IsApplicable());
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Detectors/OsDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace BenchmarkDotNet.Detectors;

public class OsDetector
{
public static readonly OsDetector Instance = new ();
public static readonly OsDetector Instance = new();
private OsDetector() { }

internal static string ExecutableExtension => IsWindows() ? ".exe" : string.Empty;
internal static string ScriptFileExtension => IsWindows() ? ".bat" : ".sh";

private readonly Lazy<OsInfo> os = new (ResolveOs);
private readonly Lazy<OsInfo> os = new(ResolveOs);
public static OsInfo GetOs() => Instance.os.Value;

private static OsInfo ResolveOs()
Expand Down
8 changes: 4 additions & 4 deletions src/BenchmarkDotNet/Diagnosers/PerfCollectProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class PerfCollectProfiler : IProfiler

private readonly PerfCollectProfilerConfig config;
private readonly DateTime creationTime = DateTime.Now;
private readonly Dictionary<BenchmarkCase, FileInfo> benchmarkToTraceFile = new ();
private readonly HashSet<string> cliPathWithSymbolsInstalled = new ();
private readonly Dictionary<BenchmarkCase, FileInfo> benchmarkToTraceFile = new();
private readonly HashSet<string> cliPathWithSymbolsInstalled = new();
private FileInfo perfCollectFile;
private Process perfCollectProcess;

Expand Down Expand Up @@ -228,7 +228,7 @@ private void EnsureSymbolsForNativeRuntime(DiagnoserActionParameters parameters)
ILogger logger = parameters.Config.GetCompositeLogger();
// We install the tool in a dedicated directory in order to always use latest version and avoid issues with broken existing configs.
string toolPath = Path.Combine(Path.GetTempPath(), "BenchmarkDotNet", "symbols");
DotNetCliCommand cliCommand = new (
DotNetCliCommand cliCommand = new(
cliPath: cliPath,
arguments: $"tool install dotnet-symbol --tool-path \"{toolPath}\"",
generateResult: null,
Expand All @@ -253,7 +253,7 @@ private void EnsureSymbolsForNativeRuntime(DiagnoserActionParameters parameters)
}

private FileInfo GetTraceFile(DiagnoserActionParameters parameters, string extension)
=> new (ArtifactFileNameHelper.GetTraceFilePath(parameters, creationTime, extension)
=> new(ArtifactFileNameHelper.GetTraceFilePath(parameters, creationTime, extension)
.Replace(" ", "_")); // perfcollect does not allow for spaces in the trace file name
}
}
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Disassemblers/Arm64Disassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ internal RuntimeSpecificData(State state)
}
}

private static readonly Dictionary<Version, RuntimeSpecificData> runtimeSpecificData = new ();
private static readonly Dictionary<Version, RuntimeSpecificData> runtimeSpecificData = new();

protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, State state, int depth, ClrMethod currentMethod, DisassemblySyntax syntax)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class Arm64InstructionFormatter
internal static string Format(Arm64Asm asm, FormatterOptions formatterOptions,
bool printInstructionAddresses, uint pointerSize, IReadOnlyDictionary<ulong, string> symbols)
{
StringBuilder output = new ();
StringBuilder output = new();
Arm64Instruction instruction = asm.Instruction;

if (printInstructionAddresses)
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Disassemblers/IntelDisassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal RuntimeSpecificData(State state)
}
}

private static readonly Dictionary<Version, RuntimeSpecificData> runtimeSpecificData = new ();
private static readonly Dictionary<Version, RuntimeSpecificData> runtimeSpecificData = new();

protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, State state, int depth, ClrMethod currentMethod, DisassemblySyntax syntax)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static ClrMdV3Disassembler CreateDisassemblerForCurrentArchitecture()
};

private Settings BuildDisassemblerSettings(DiagnoserActionParameters parameters)
=> new (
=> new(
processId: parameters.Process.Id,
typeName: $"BenchmarkDotNet.Autogenerated.Runnable_{parameters.BenchmarkId.Value}",
methodName: DisassemblerConstants.DisassemblerEntryMethodName,
Expand Down
6 changes: 3 additions & 3 deletions src/BenchmarkDotNet/Engines/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Engine : IEngine
private bool EvaluateOverhead { get; }
private bool MemoryRandomization { get; }

private readonly List<Measurement> jittingMeasurements = new (10);
private readonly List<Measurement> jittingMeasurements = new(10);
private readonly bool includeExtraStats;
private readonly Random random;

Expand Down Expand Up @@ -351,8 +351,8 @@ private sealed class Impl
// ManualResetEvent(Slim) allocates when it is waited and yields the thread,
// so we use Monitor.Wait instead which does not allocate managed memory.
// This behavior is not documented, but was observed with the VS Profiler.
private readonly object hangLock = new ();
private readonly ManualResetEventSlim enteredFinalizerEvent = new (false);
private readonly object hangLock = new();
private readonly ManualResetEventSlim enteredFinalizerEvent = new(false);

~Impl()
{
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Engines/EngineActualStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public EngineActualStageAuto(Job targetJob, IResolver resolver, IterationMode it
measurementsForStatistics = GetMeasurementList();
}

internal override List<Measurement> GetMeasurementList() => new (maxIterationCount);
internal override List<Measurement> GetMeasurementList() => new(maxIterationCount);

internal override bool GetShouldRunIteration(List<Measurement> measurements, ref long invokeCount)
{
Expand Down Expand Up @@ -88,7 +88,7 @@ internal sealed class EngineActualStageSpecific(int maxIterationCount, Iteration
{
private int iterationCount = 0;

internal override List<Measurement> GetMeasurementList() => new (maxIterationCount);
internal override List<Measurement> GetMeasurementList() => new(maxIterationCount);

internal override bool GetShouldRunIteration(List<Measurement> measurements, ref long invokeCount)
=> ++iterationCount <= maxIterationCount;
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Engines/EngineWarmupStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class EngineWarmupStageAuto(IterationMode iterationMode, int min
private readonly int minIterationCount = minIterationCount;
private readonly int maxIterationCount = maxIterationCount;

internal override List<Measurement> GetMeasurementList() => new (maxIterationCount);
internal override List<Measurement> GetMeasurementList() => new(maxIterationCount);

internal override bool GetShouldRunIteration(List<Measurement> measurements, ref long invokeCount)
{
Expand Down Expand Up @@ -70,7 +70,7 @@ internal sealed class EngineWarmupStageSpecific(int maxIterationCount, Iteration
{
private int iterationCount = 0;

internal override List<Measurement> GetMeasurementList() => new (maxIterationCount);
internal override List<Measurement> GetMeasurementList() => new(maxIterationCount);

internal override bool GetShouldRunIteration(List<Measurement> measurements, ref long invokeCount)
=> ++iterationCount <= maxIterationCount;
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Environments/HostEnvironmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static string GetInformation()
return sb.ToString();
}

internal BdnHostInfo ToPerfonar() => new ()
internal BdnHostInfo ToPerfonar() => new()
{
Cpu = Cpu.Value,
Os = Os.Value,
Expand Down
22 changes: 11 additions & 11 deletions src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace BenchmarkDotNet.Environments
{
public class CoreRuntime : Runtime
{
public static readonly CoreRuntime Core20 = new (RuntimeMoniker.NetCoreApp20, "netcoreapp2.0", ".NET Core 2.0");
public static readonly CoreRuntime Core21 = new (RuntimeMoniker.NetCoreApp21, "netcoreapp2.1", ".NET Core 2.1");
public static readonly CoreRuntime Core22 = new (RuntimeMoniker.NetCoreApp22, "netcoreapp2.2", ".NET Core 2.2");
public static readonly CoreRuntime Core30 = new (RuntimeMoniker.NetCoreApp30, "netcoreapp3.0", ".NET Core 3.0");
public static readonly CoreRuntime Core31 = new (RuntimeMoniker.NetCoreApp31, "netcoreapp3.1", ".NET Core 3.1");
public static readonly CoreRuntime Core50 = new (RuntimeMoniker.Net50, "net5.0", ".NET 5.0");
public static readonly CoreRuntime Core60 = new (RuntimeMoniker.Net60, "net6.0", ".NET 6.0");
public static readonly CoreRuntime Core70 = new (RuntimeMoniker.Net70, "net7.0", ".NET 7.0");
public static readonly CoreRuntime Core80 = new (RuntimeMoniker.Net80, "net8.0", ".NET 8.0");
public static readonly CoreRuntime Core90 = new (RuntimeMoniker.Net90, "net9.0", ".NET 9.0");
public static readonly CoreRuntime Core10_0 = new (RuntimeMoniker.Net10_0, "net10.0", ".NET 10.0");
public static readonly CoreRuntime Core20 = new(RuntimeMoniker.NetCoreApp20, "netcoreapp2.0", ".NET Core 2.0");
public static readonly CoreRuntime Core21 = new(RuntimeMoniker.NetCoreApp21, "netcoreapp2.1", ".NET Core 2.1");
public static readonly CoreRuntime Core22 = new(RuntimeMoniker.NetCoreApp22, "netcoreapp2.2", ".NET Core 2.2");
public static readonly CoreRuntime Core30 = new(RuntimeMoniker.NetCoreApp30, "netcoreapp3.0", ".NET Core 3.0");
public static readonly CoreRuntime Core31 = new(RuntimeMoniker.NetCoreApp31, "netcoreapp3.1", ".NET Core 3.1");
public static readonly CoreRuntime Core50 = new(RuntimeMoniker.Net50, "net5.0", ".NET 5.0");
public static readonly CoreRuntime Core60 = new(RuntimeMoniker.Net60, "net6.0", ".NET 6.0");
public static readonly CoreRuntime Core70 = new(RuntimeMoniker.Net70, "net7.0", ".NET 7.0");
public static readonly CoreRuntime Core80 = new(RuntimeMoniker.Net80, "net8.0", ".NET 8.0");
public static readonly CoreRuntime Core90 = new(RuntimeMoniker.Net90, "net9.0", ".NET 9.0");
public static readonly CoreRuntime Core10_0 = new(RuntimeMoniker.Net10_0, "net10.0", ".NET 10.0");

public static CoreRuntime Latest => Core10_0; // when dotnet/runtime branches for 11.0, this will need to get updated

Expand Down
12 changes: 6 additions & 6 deletions src/BenchmarkDotNet/Environments/Runtimes/MonoRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace BenchmarkDotNet.Environments
{
public class MonoRuntime : Runtime, IEquatable<MonoRuntime>
{
public static readonly MonoRuntime Default = new ("Mono");
public static readonly MonoRuntime Mono60 = new ("Mono with .NET 6.0", RuntimeMoniker.Mono60, "net6.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono70 = new ("Mono with .NET 7.0", RuntimeMoniker.Mono70, "net7.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono80 = new ("Mono with .NET 8.0", RuntimeMoniker.Mono80, "net8.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono90 = new ("Mono with .NET 9.0", RuntimeMoniker.Mono90, "net9.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono10_0 = new ("Mono with .NET 10.0", RuntimeMoniker.Mono10_0, "net10.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Default = new("Mono");
public static readonly MonoRuntime Mono60 = new("Mono with .NET 6.0", RuntimeMoniker.Mono60, "net6.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono70 = new("Mono with .NET 7.0", RuntimeMoniker.Mono70, "net7.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono80 = new("Mono with .NET 8.0", RuntimeMoniker.Mono80, "net8.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono90 = new("Mono with .NET 9.0", RuntimeMoniker.Mono90, "net9.0", isDotNetBuiltIn: true);
public static readonly MonoRuntime Mono10_0 = new("Mono with .NET 10.0", RuntimeMoniker.Mono10_0, "net10.0", isDotNetBuiltIn: true);

public string CustomPath { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Helpers/AwaitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private class ValueTaskWaiter

private ValueTaskWaiter()
{
resetEvent = new ();
resetEvent = new();
awaiterCallback = resetEvent.Set;
}

Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Helpers/UnitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BenchmarkDotNet.Helpers;

public static class UnitHelper
{
public static readonly UnitPresentation DefaultPresentation = new (true, 0, gap: true);
public static readonly UnitPresentation DefaultPresentation = new(true, 0, gap: true);

public static string ToDefaultString(this TimeInterval timeInterval, string? format = null) => timeInterval.ToString(format, null, DefaultPresentation);
}
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Helpers/XUnitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace BenchmarkDotNet.Helpers;
internal static class XUnitHelper
{
public static Lazy<bool> IsIntegrationTest =
new (() => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.GetName().Name == "BenchmarkDotNet.IntegrationTests"));
new(() => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.GetName().Name == "BenchmarkDotNet.IntegrationTests"));
}
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Jobs/EnvironmentMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void SetEnvironmentVariable(EnvironmentVariable variable)

internal Runtime GetRuntime() => HasValue(RuntimeCharacteristic) ? Runtime : RuntimeInformation.GetCurrentRuntime();

internal BdnEnvironment ToPerfonar() => new ()
internal BdnEnvironment ToPerfonar() => new()
{
Jit = HasValue(JitCharacteristic) ? Jit : null,
Runtime = HasValue(RuntimeCharacteristic) ? Runtime?.RuntimeMoniker : null,
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Jobs/RunMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public bool MemoryRandomization
set => MemoryRandomizationCharacteristic[this] = value;
}

internal BdnExecution ToPerfonar() => new ()
internal BdnExecution ToPerfonar() => new()
{
LaunchCount = HasValue(LaunchCountCharacteristic) ? LaunchCount : null,
WarmupCount = HasValue(WarmupCountCharacteristic) ? WarmupCount : null,
Expand Down
Loading