Skip to content

Instantly share code, notes, and snippets.

@davepcallan
Created February 21, 2023 08:03
Show Gist options
  • Save davepcallan/2f85b68da12458496a92bc5168084481 to your computer and use it in GitHub Desktop.
Save davepcallan/2f85b68da12458496a92bc5168084481 to your computer and use it in GitHub Desktop.
OrdinalIgnoreCase .NET 7 v .NET 8 benchmarks
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3.2064" />
</ItemGroup>
</Project>
using BenchmarkDotNet.Running;
internal class Program
{
private static void Main(string[] args)
{
//choose on command line from multiple benchmarks
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run();
}
}
using System.Collections.Generic;
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
namespace BenchmarkDotNet.Samples
{
[Config(typeof(Config))]
[HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)]
[SimpleJob(RuntimeMoniker.Net70, baseline: true)]
[SimpleJob(RuntimeMoniker.Net80)]
public class StringCompareBenchmarks
{
[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[]
{
@"dotnet",
@"dotNet",
};
yield return new object[]
{
@"Dave Callan",
@"dave callan",
};
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()
{
SummaryStyle =
SummaryStyle.Default.WithRatioStyle(RatioStyle.Percentage);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment