-
Notifications
You must be signed in to change notification settings - Fork 274
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
String Comparers benchmarks #535
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f3447d4
initial implementation of StringComparer benchmarks
adamsitnik be25347
handle missing libgdiplus on some Linux distros
adamsitnik 0f13586
Revert "handle missing libgdiplus on some Linux distros"
adamsitnik 63af2eb
update the comment
adamsitnik 1ac69ca
add Ordinal and InvariantCulture
adamsitnik 829f713
describe the test cases
adamsitnik 64db162
remove the CompareLastCharDifferent benchmark which does not really a…
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/benchmarks/micro/corefx/System.Runtime/Perf.StringComparer.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Extensions; | ||
using MicroBenchmarks; | ||
|
||
namespace System.Tests | ||
{ | ||
[BenchmarkCategory(Categories.CoreFX, Categories.CoreCLR)] | ||
public class Perf_StringComparer | ||
{ | ||
[Params( | ||
128, // stackalloc path | ||
1024 * 256, // ArrayPool.Shared.Rent without allocation | ||
2 * 1024 * 1024)] // ArrayPool.Shared.Rent WITH allocation | ||
public int Count { get; set; } | ||
|
||
[Params( | ||
StringComparison.Ordinal, StringComparison.OrdinalIgnoreCase, | ||
StringComparison.InvariantCulture, StringComparison.InvariantCultureIgnoreCase)] | ||
public StringComparison Comparison { get; set; } | ||
|
||
private string _input, _same; | ||
private StringComparer _comparer; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_comparer = GetStringComparer(); | ||
char[] characters = ValuesGenerator.Array<char>(Count); | ||
_input = new string(characters); | ||
_same = new string(characters); | ||
} | ||
|
||
[Benchmark] | ||
public int GetStringHashCode() => _comparer.GetHashCode(_input); | ||
|
||
[Benchmark] | ||
public int CompareSame() => _comparer.Compare(_input, _same); | ||
|
||
private StringComparer GetStringComparer() | ||
{ | ||
switch (Comparison) | ||
{ | ||
case StringComparison.CurrentCulture: | ||
return StringComparer.CurrentCulture; | ||
case StringComparison.CurrentCultureIgnoreCase: | ||
return StringComparer.CurrentCultureIgnoreCase; | ||
case StringComparison.InvariantCulture: | ||
return StringComparer.InvariantCulture; | ||
case StringComparison.InvariantCultureIgnoreCase: | ||
return StringComparer.InvariantCultureIgnoreCase; | ||
case StringComparison.Ordinal: | ||
return StringComparer.Ordinal; | ||
case StringComparison.OrdinalIgnoreCase: | ||
return StringComparer.OrdinalIgnoreCase; | ||
default: | ||
throw new NotSupportedException($"{Comparison} is not supported"); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the covered cases :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Thanks for the comments too