Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2023 09:24
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
String equals benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
namespace BenchmarkDotNet.Samples
[HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)]
public class StringComparisonBenchmarks
private class Config : ManualConfig
public Config()
SummaryStyle =
private string str1 = "HELLO WORLD";
private string str2 = "hello world";
[Benchmark(Baseline = true)]
public bool Equals_OrdinalIgnoreCase() => string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase);
public bool Compare_OrdinalIgnoreCase() => string.Compare(str1, str2, StringComparison.OrdinalIgnoreCase) == 0;
public bool ToLower() => str1.ToLower() == str2.ToLower();
public bool ToUpper() => str1.ToUpper() == str2.ToUpper();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment