Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Benchmarks for #117431 (EgorBo) #427

@EgorBot

Description

@EgorBot

Processing dotnet/runtime#117431 (comment) command:

Command

-arm -amd

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

public class BestCase
{
    string _empty;
    [Benchmark] public bool Best_StringEq_Empty() => _empty == "";

    string _short = "Hi";
    [Benchmark] public bool Best_StringEq_Short() => _short == "H1";
    [Benchmark] public bool Best_StringEq_Short_IgnoreCase() => string.Equals(_short, "H1", StringComparison.OrdinalIgnoreCase);

    string _medium = "Hello World";
    [Benchmark] public bool Best_StringEq_Medium() => _medium == "Hello World2";
    [Benchmark] public bool Best_StringEq_Medium_IgnoreCase() => string.Equals(_medium, "Hello World2", StringComparison.OrdinalIgnoreCase);

    string _long = "using System.Runtime.CompilerServices";
    [Benchmark] public bool Best_StringEq_Long() => _long == "using System.Runtime.CompilerServices";
    [Benchmark] public bool Best_StringEq_Long_IgnoreCase() => string.Equals(_long, "using System.Runtime.CompilerServices", StringComparison.OrdinalIgnoreCase);
}

public class WorstCase
{
    // Don't know how to create an empty string that will be different from the interned one
    // I think it's almost impossible in practice.

    string _short = "Qi";
    [Benchmark] public bool Worst_StringEq_Short() => _short == "H1";
    [Benchmark] public bool Worst_StringEq_Short_IgnoreCase() => string.Equals(_short, "H1", StringComparison.OrdinalIgnoreCase);

    string _medium = "Qello World";
    [Benchmark] public bool Worst_StringEq_Medium() => _medium == "Hello World2";
    [Benchmark] public bool Worst_StringEq_Medium_IgnoreCase() => string.Equals(_medium, "Hello World2", StringComparison.OrdinalIgnoreCase);

    string _long = "Qsing System.Runtime.CompilerServices";
    [Benchmark] public bool Worst_StringEq_Long() => _long == "using System.Runtime.CompilerServices";
    [Benchmark] public bool Worst_StringEq_Long_IgnoreCase() => string.Equals(_long, "using System.Runtime.CompilerServices", StringComparison.OrdinalIgnoreCase);
}

(EgorBot will reply in this issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions