Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve String.EndsWith for OrdinalIgnoreCase #72750

Merged
merged 1 commit into from Jul 25, 2022

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jul 24, 2022

Use Equals instead of Compare. The same method is used for String.StartsWith

static readonly string TestStr = typeof(object).Assembly.Location;

[Benchmark]
public bool EndsWith_small() => 
    TestStr.EndsWith(".DLL", StringComparison.OrdinalIgnoreCase);

[Benchmark]
public bool EndsWith_large() => 
    TestStr.EndsWith("system.private.corelib.dll", StringComparison.OrdinalIgnoreCase);
Method Toolchain Mean Error StdDev Ratio
EndsWith_small \Core_Root\corerun.exe 4.502 ns 0.0076 ns 0.0064 ns 0.54
EndsWith_small \Core_Root_base\corerun.exe 8.368 ns 0.0113 ns 0.0106 ns 1.00
EndsWith_large \Core_Root\corerun.exe 12.669 ns 0.0456 ns 0.0404 ns 0.60
EndsWith_large \Core_Root_base\corerun.exe 21.006 ns 0.0429 ns 0.0358 ns 1.00

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost assigned EgorBo Jul 24, 2022
@EgorBo EgorBo merged commit e83493e into dotnet:main Jul 25, 2022
@dotnet dotnet locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants