Skip to content

ObjectComparison: .NET 10, null-safe comparers, copy-per-call benchmark - #2378

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/75645-csharp-icomparable-icomparer-comparison-delegate
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/75645-csharp-icomparable-icomparer-comparison-delegate

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Moves the ObjectComparison sample to net10.0 with current BenchmarkDotNet, xunit and test SDK packages. The IComparer helpers and the Comparison delegate methods now put nulls first instead of returning 0, which broke the comparison contract and left arrays with nulls unsorted. The benchmark copies a shuffled source into a working array before each sort, so every call sorts unsorted data, and tests two sizes. Program.cs adds a lambda sort by Name and passes args to BenchmarkRunner, and the tests now check exact orders, nulls, random input and SortedSet with Comparer.Create.

Targets net10.0 with BenchmarkDotNet 0.15.8, xunit 2.9.3, xunit.runner.visualstudio 4.0.1, Microsoft.NET.Test.Sdk 18.11.0 and coverlet.collector 10.1.0. The comparers and Comparison delegate methods now sort nulls first instead of returning 0, the benchmark copies a shuffled source before each sort, Program.cs adds a lambda sort by Name and passes args to BenchmarkRunner, and the tests cover descending order, the lambda, nulls, random input and SortedSet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant