Method | ComparisonMode | Mean | Error | StdDev |
---|---|---|---|---|
TestSorting | InvariantCulture | 954.5 ms | 18.25 ms | 17.07 ms |
TestSorting | Ordinal | 110.8 ms | 1.27 ms | 1.19 ms |
TestSorting | OrdinalIgnoreCase | 187.6 ms | 3.32 ms | 3.10 ms |
Created
February 21, 2024 10:13
-
-
Save bdach/97d06de3531a5b4821fe3acf39618d3e to your computer and use it in GitHub Desktop.
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
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | |
// See the LICENCE file in the repository root for full licence text. | |
using System; | |
using BenchmarkDotNet.Attributes; | |
namespace osu.Game.Benchmarks | |
{ | |
public class BenchmarkStringComparison | |
{ | |
private string[] strings = null!; | |
[Params(StringComparison.Ordinal, StringComparison.OrdinalIgnoreCase, StringComparison.InvariantCulture)] | |
public StringComparison ComparisonMode { get; set; } | |
[GlobalSetup] | |
public void GlobalSetUp() | |
{ | |
strings = new string[10000]; | |
for (int i = 0; i < strings.Length; ++i) | |
strings[i] = Guid.NewGuid().ToString(); | |
for (int i = 0; i < strings.Length; ++i) | |
{ | |
if (i % 2 == 0) | |
strings[i] = strings[i].ToUpperInvariant(); | |
} | |
} | |
[Benchmark] | |
public void TestSorting() | |
{ | |
for (int i = 0; i < strings.Length; ++i) | |
{ | |
for (int j = i + 1; j < strings.Length; ++j) | |
_ = string.Compare(strings[i], strings[j], ComparisonMode); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment