Skip to content

Instantly share code, notes, and snippets.

@davepcallan
Last active April 23, 2024 16:21
Show Gist options
  • Save davepcallan/197b22fe4c5f76ecec717f845d033939 to your computer and use it in GitHub Desktop.
Save davepcallan/197b22fe4c5f76ecec717f845d033939 to your computer and use it in GitHub Desktop.
In .NET 9 string.contains("X") will delegate to string.contains('X')
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
[Config(typeof(Config))]
[HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)]
[MemoryDiagnoser]
public class StringContains
{
readonly string _inputString =
"Permission is hereby granted, free of charge, to any person obtaining " +
"a copy of the Unicode data files and any associated documentation";
[Benchmark]
public bool Contains_string() => _inputString.Contains("X");
private class Config : ManualConfig
{
public Config()
{
AddJob(Job.Default.WithId(".NET 8").WithRuntime(CoreRuntime.Core80).AsBaseline());
AddJob(Job.Default.WithId(".NET 9").WithRuntime(CoreRuntime.Core90));
SummaryStyle =
SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment