Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Jul 28, 2023
1 parent f8ab518 commit b912a8e
Show file tree
Hide file tree
Showing 68 changed files with 28 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace BenchmarkDotNet.Samples
public class IntroComparableComplexParam
{
[ParamsSource(nameof(ValuesForA))]
public ComplexParam A { get; set; }
public ComplexParam? A { get; set; }

public IEnumerable<ComplexParam> ValuesForA => new[] { new ComplexParam(1, "First"), new ComplexParam(2, "Second") };

[Benchmark]
public object Benchmark() => A;
public object? Benchmark() => A;

// Only non generic IComparable is required to provide custom order behavior, but implementing IComparable<> too is customary.
public class ComplexParam : IComparable<ComplexParam>, IComparable
Expand All @@ -29,7 +29,7 @@ public ComplexParam(int value, string name)

public override string ToString() => Name;

public int CompareTo(ComplexParam other) => other == null ? 1 : Value.CompareTo(other.Value);
public int CompareTo(ComplexParam? other) => other == null ? 1 : Value.CompareTo(other.Value);

public int CompareTo(object obj) => obj is ComplexParam other ? CompareTo(other) : throw new ArgumentException();
}
Expand Down
1 change: 0 additions & 1 deletion samples/BenchmarkDotNet.Samples/IntroDisassemblyDry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;

namespace BenchmarkDotNet.Samples
{
Expand Down
12 changes: 6 additions & 6 deletions samples/BenchmarkDotNet.Samples/IntroMemoryRandomization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ public class IntroMemoryRandomization
[Params(512 * 4)]
public int Size;

private int[] _array;
private int[] _destination;
private int[] array;
private int[] destination;

[GlobalSetup]
public void Setup()
{
_array = new int[Size];
_destination = new int[Size];
array = new int[Size];
destination = new int[Size];
}

[Benchmark]
[MemoryRandomization(false)]
public void Array_RandomizationDisabled() => Array.Copy(_array, _destination, Size);
public void Array_RandomizationDisabled() => Array.Copy(array, destination, Size);

[Benchmark]
[MemoryRandomization(true)]
[MaxIterationCount(40)] // the benchmark becomes multimodal and need a lower limit of max iterations than the default
public void Array_RandomizationEnabled() => Array.Copy(_array, _destination, Size);
public void Array_RandomizationEnabled() => Array.Copy(array, destination, Size);
}
}
1 change: 0 additions & 1 deletion samples/BenchmarkDotNet.Samples/IntroWasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System.IO;
using BenchmarkDotNet.Toolchains;
using BenchmarkDotNet.Toolchains.DotNetCli;
using BenchmarkDotNet.Toolchains.MonoWasm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ public class GenericTypeArgumentsAttribute : Attribute
public Type[] GenericTypeArguments { get; }

public GenericTypeArgumentsAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type)
=> GenericTypeArguments = new Type[] { type };
=> GenericTypeArguments = new[] { type };

public GenericTypeArgumentsAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type1,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type2)
=> GenericTypeArguments = new Type[] { type1, type2 };
=> GenericTypeArguments = new[] { type1, type2 };

public GenericTypeArgumentsAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type1,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type2,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type3)
=> GenericTypeArguments = new Type[] { type1, type2, type3 };
=> GenericTypeArguments = new[] { type1, type2, type3 };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace BenchmarkDotNet.Attributes
/// </summary>
public abstract class TargetedAttribute : Attribute
{
public string[] Targets { get; set; }
public string[] Targets { get; set; } = new string[0];

/// <summary>
/// Target method for attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;
using JetBrains.Annotations;
using Microsoft.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tracing.Parsers;
using Microsoft.Diagnostics.Tracing.Session;

namespace BenchmarkDotNet.Diagnostics.Windows
{
Expand Down
2 changes: 0 additions & 2 deletions src/BenchmarkDotNet.Diagnostics.dotTrace/DotTraceDiagnoser.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Portability;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Loggers;
using JetBrains.Profiler.SelfApi;
using ILogger = BenchmarkDotNet.Loggers.ILogger;
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Analysers/Conclusion.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Analysers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Globalization;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;
using Perfolizer.Mathematics.Multimodality;

namespace BenchmarkDotNet.Analysers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using BenchmarkDotNet.Mathematics;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Columns
{
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Columns/BaselineRatioColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using BenchmarkDotNet.Mathematics;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Columns
{
Expand Down
2 changes: 0 additions & 2 deletions src/BenchmarkDotNet/Configs/DebugConfig.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Diagnosers;
Expand All @@ -10,7 +9,6 @@
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.InProcess.Emit;
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Configs/IConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Configs
{
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Configs/ImmutableConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void AddWarning(string message)
AddWarning($"The exporter {exporterType} of {diagnoser.GetType().Name} is already present in configuration. There may be unexpected results.");
}
mergeDictionary[exporterType] = exporter;
};
}

var result = mergeDictionary.Values.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Running;
using JetBrains.Annotations;

namespace BenchmarkDotNet.ConsoleArguments
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ internal static IReadOnlyList<Element> Prettify(DisassembledMethod method, Disas
}

// call to a known method
if (disassemblyResult.AddressToNameMapping.ContainsKey(referencedAddress))
if (disassemblyResult.AddressToNameMapping.TryGetValue(referencedAddress, out string? referencedName))
{
string comment = string.Empty;
if (asm.IsReferencedAddressIndirect)
{
comment = "; " + disassemblyResult.AddressToNameMapping[referencedAddress];
comment = "; " + referencedName;
}
prettified.Add(new Element(CodeFormatter.Format(asm, formatterWithGlobalSymbols, config.PrintInstructionAddresses, disassemblyResult.PointerSize, disassemblyResult.AddressToNameMapping) + comment, asm));
continue;
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Disassemblers/MonoDisassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Running;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Disassemblers
{
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Engines/Engine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Engines/EnginePilotStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;
using Perfolizer.Horology;

namespace BenchmarkDotNet.Engines
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Engines
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Reports;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Engines
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using JetBrains.Annotations;

namespace BenchmarkDotNet.Engines
{
public struct StoppingResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime;
using BenchmarkDotNet.Engines;
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Environments/OsBrandStringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
using BenchmarkDotNet.Extensions;

namespace BenchmarkDotNet.Environments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ private static string GetBrandStyledActualFrequency(Frequency? frequency)
[SuppressMessage("ReSharper", "StringLiteralTypo")]
internal static string? ParseIntelCoreMicroarchitecture(string modelNumber)
{
if (KnownMicroarchitectures.Value.ContainsKey(modelNumber))
return KnownMicroarchitectures.Value[modelNumber];
if (KnownMicroarchitectures.Value.TryGetValue(modelNumber, out string? microarchitecture))
return microarchitecture;

if (modelNumber.Length >= 3 && modelNumber.Substring(0, 3).All(char.IsDigit) &&
(modelNumber.Length == 3 || !char.IsDigit(modelNumber[3])))
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal static bool TryGetVersionFromProductInfo(string productVersion, string
if (productName.IndexOf(".NET Framework", StringComparison.OrdinalIgnoreCase) >= 0)
{
const string releaseVersionPrefix = "release/";
int releaseVersionIndex = productVersion.IndexOf(releaseVersionPrefix);
int releaseVersionIndex = productVersion.IndexOf(releaseVersionPrefix, StringComparison.Ordinal);
if (releaseVersionIndex > 0)
{
string releaseVersion = GetParsableVersionPart(productVersion.Substring(releaseVersionIndex + releaseVersionPrefix.Length));
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Exporters/Csv/CsvHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Exporters.Csv
{
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Extensions/CultureInfoExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Globalization;
using BenchmarkDotNet.Helpers;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Extensions
{
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Extensions/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.CoreRun;
using BenchmarkDotNet.Toolchains.MonoAotLLVM;
using JetBrains.Annotations;


Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Filters/GlobFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using BenchmarkDotNet.Exporters;
Expand Down
2 changes: 0 additions & 2 deletions src/BenchmarkDotNet/Helpers/AsciiHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using JetBrains.Annotations;

namespace BenchmarkDotNet.Helpers
{
internal static class AsciiHelper
Expand Down
12 changes: 6 additions & 6 deletions src/BenchmarkDotNet/Helpers/FrameworkVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ internal static string GetFrameworkReleaseVersion()
internal static string MapToReleaseVersion(string servicingVersion)
{
// the following code assumes that .NET 4.6.1 is the oldest supported version
if (string.Compare(servicingVersion, "4.6.2") < 0)
if (string.CompareOrdinal(servicingVersion, "4.6.2") < 0)
return "4.6.1";
if (string.Compare(servicingVersion, "4.7") < 0)
if (string.CompareOrdinal(servicingVersion, "4.7") < 0)
return "4.6.2";
if (string.Compare(servicingVersion, "4.7.1") < 0)
if (string.CompareOrdinal(servicingVersion, "4.7.1") < 0)
return "4.7";
if (string.Compare(servicingVersion, "4.7.2") < 0)
if (string.CompareOrdinal(servicingVersion, "4.7.2") < 0)
return "4.7.1";
if (string.Compare(servicingVersion, "4.8") < 0)
if (string.CompareOrdinal(servicingVersion, "4.8") < 0)
return "4.7.2";
if (string.Compare(servicingVersion, "4.8.9") < 0)
if (string.CompareOrdinal(servicingVersion, "4.8.9") < 0)
return "4.8";

return "4.8.1"; // most probably the last major release of Full .NET Framework
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using BenchmarkDotNet.Loggers;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Helpers
{
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Helpers/SectionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Helpers
{
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Helpers/Taskbar/TaskbarProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ internal static void SetState(IntPtr consoleWindowHandle, IntPtr consoleHandle,
case TaskbarProgressState.Warning:
Console.Write("\x1b]9;4;4;0\x1b\\");
break;
};
}
SetConsoleMode(consoleHandle, previousConsoleMode);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Jobs/EnvironmentVariable.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;

namespace BenchmarkDotNet.Jobs
{
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Jobs/Job.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BenchmarkDotNet.Characteristics;
using JetBrains.Annotations;
using System;
using System.Diagnostics.CodeAnalysis;

namespace BenchmarkDotNet.Jobs
Expand Down
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Jobs/NugetReference.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace BenchmarkDotNet.Jobs
Expand Down
Loading

0 comments on commit b912a8e

Please sign in to comment.