Skip to content

CompareArrays: retarget net10.0, split Article comparer, rename object-equality benchmarks - #2141

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/68208-csharp-compare-arrays
Open

CompareArrays: retarget net10.0, split Article comparer, rename object-equality benchmarks#2141
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/68208-csharp-compare-arrays

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Supports the refresh of https://code-maze.com/csharp-compare-arrays/

  • Retarget CompareArrays, BenchmarkRunner and Tests from net6.0 to net10.0.
  • BenchmarkDotNet 0.13.1 -> 0.15.8, MSTest 2.2.7 -> 3.10.4, Microsoft.NET.Test.Sdk 16.11.0 -> 18.9.0, coverlet.collector 3.1.0 -> 10.0.1.
  • Comparer fix. Article implemented IEqualityComparer<Article> on the data class itself, and GetHashCode(Article obj) returned base.GetHashCode() - the hash of the comparer instance, not of obj. SequenceEqual never calls it, so the sample worked and the bug was invisible; the same class used with Distinct, GroupBy, HashSet<T> or a dictionary key would misbehave. Split into a plain Article data class plus ArticleComparer : IEqualityComparer<Article> with a real GetHashCode combining Title and LastUpdate.
  • Renames. EnumerableEquals -> ObjectEquals and EnumerableReferenceEquals -> ObjectReferenceEquals in ArrayComparer, ArrayComparerBenchmark, Program and Tests. Neither Equals nor ReferenceEquals is declared on System.Linq.Enumerable; both call sites are the unqualified form resolving through the containing class from object. BenchmarkDotNet generates its Method column from these names, so the old names contradicted the article's own headings.

Build: 0 warnings, 0 errors. Tests: 14/14 passing on net10.0.

…t-equality benchmarks

- Retarget CompareArrays, BenchmarkRunner and Tests from net6.0 to net10.0.
- BenchmarkDotNet 0.13.1 -> 0.15.8, MSTest 2.2.7 -> 3.10.4, Test.Sdk 16.11.0 -> 18.9.0,
  coverlet.collector 3.1.0 -> 10.0.1.
- Article was its own IEqualityComparer<Article> and GetHashCode(Article obj) returned
  base.GetHashCode(), i.e. the hash of the comparer instance rather than of obj. Split it
  into a plain Article data class plus ArticleComparer : IEqualityComparer<Article> with a
  real GetHashCode combining Title and LastUpdate; EnumerableSequenceEqual(Article[], Article[])
  now passes new ArticleComparer().
- Rename EnumerableEquals -> ObjectEquals and EnumerableReferenceEquals -> ObjectReferenceEquals
  in ArrayComparer, ArrayComparerBenchmark, Program and Tests. Both call sites are the
  unqualified Equals/ReferenceEquals resolving through the containing class from object;
  neither member is declared on Enumerable, and the benchmark's Method column is generated
  from these names.

Build: 0 warnings, 0 errors. Tests: 14/14 passing on net10.0.
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