Created
August 3, 2023 11:33
-
-
Save davepcallan/e955cb5c01fbc5e03fcbc47c1766810e to your computer and use it in GitHub Desktop.
.NET 7 v .NET String.Equals OrdinalIgnoreCase benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Columns; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Jobs; | |
using BenchmarkDotNet.Reports; | |
using BenchmarkDotNet.Environments; | |
namespace Benchmarks | |
{ | |
[Config(typeof(Config))] | |
[HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)] | |
[MemoryDiagnoser] | |
public class StringCompareDotNet8Benchmarks | |
{ | |
[Benchmark] | |
[ArgumentsSource(nameof(TestData))] | |
public bool EqualsIgnoreCase(string s1, string s2) => | |
s1.Equals(s2, StringComparison.OrdinalIgnoreCase); | |
public static IEnumerable<object[]> TestData() | |
{ | |
yield return new object[] | |
{ | |
@"Hi!", // 3 chars (to make sure overhead is not big) | |
@"HI!", | |
}; | |
yield return new object[] | |
{ | |
@"hello!!!", // 8 chars (switches to SIMD) | |
@"HELLO!!!", | |
}; | |
yield return new object[] | |
{ | |
@"hello world", // 11 chars (1xV128 + trailing elements) | |
@"HELLO WORLD", | |
}; | |
yield return new object[] | |
{ | |
@"C:\prj\runtime-main\src\coreclr\CMakeLists.txt", // 46 chars (5xV128 + trailing elements) | |
@"C:\prj\runtime-main\src\CORECLR\CMakeLists.txt", | |
}; | |
yield return new object[] | |
{ | |
@"Good bug reports make it easier for maintainers to verify and root cause the underlying problem. The better a bug report, the faster the problem will be resolved. Ideally, a bug report should contain the following information:", // 226 chars | |
@"GOOD bug reports make it easier for maintainers to verify and root cause the underlying problem. The better a bug report, the faster the problem will be resolved. Ideally, a bug report should contain the following information:", | |
}; | |
} | |
private class Config : ManualConfig | |
{ | |
public Config() | |
{ | |
//setting compilation configs explicitly to avoid confusion | |
AddJob(Job.Default.WithId(".NET7") | |
.WithRuntime(CoreRuntime.Core70) | |
.WithBaseline(true) | |
.WithEnvironmentVariables( | |
new EnvironmentVariable("DOTNET_ReadyToRun", "0"), // Disable AOT | |
new EnvironmentVariable("DOTNET_TC_QuickJitForLoops", "1"), // Enable Quick Jit for loop | |
new EnvironmentVariable("DOTNET_TieredPGO", "1"))); // Turn on layered PGO | |
AddJob(Job.Default.WithId(".NET8") | |
.WithRuntime(CoreRuntime.Core80) | |
.WithEnvironmentVariables( | |
new EnvironmentVariable("DOTNET_ReadyToRun", "0"), // Disable AOT | |
new EnvironmentVariable("DOTNET_TC_QuickJitForLoops", "1"), // Enable Quick Jit for loop | |
new EnvironmentVariable("DOTNET_TieredPGO", "1"))); // Turn on layered PGO | |
SummaryStyle = | |
SummaryStyle.Default.WithRatioStyle(RatioStyle.Percentage); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment