-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of Contains (#174)
- Loading branch information
Showing
67 changed files
with
1,116 additions
and
2,914 deletions.
There are no files selected for viewing
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
111 changes: 111 additions & 0 deletions
111
NetFabric.Hyperlinq.Benchmarks/Contains.DefaultComparer.Benchmarks.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,111 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using JM.LinqFaster; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NetFabric.Hyperlinq.Benchmarks | ||
{ | ||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | ||
[CategoriesColumn] | ||
[MemoryDiagnoser] | ||
[MarkdownExporterAttribute.GitHub] | ||
public class ContainsDefaultComparerBenchmarks : BenchmarksBase | ||
{ | ||
[BenchmarkCategory("Array")] | ||
[Benchmark(Baseline = true)] | ||
public bool Linq_Array() => | ||
System.Linq.Enumerable.Contains(array, Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Enumerable_Value")] | ||
[Benchmark(Baseline = true)] | ||
public bool Linq_Enumerable_Value() => | ||
System.Linq.Enumerable.Contains(enumerableValue, Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Collection_Value")] | ||
[Benchmark(Baseline = true)] | ||
public bool Linq_Collection_Value() => | ||
System.Linq.Enumerable.Contains(collectionValue, Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("List_Value")] | ||
[Benchmark(Baseline = true)] | ||
public bool Linq_List_Value() => | ||
System.Linq.Enumerable.Contains(listValue, Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Enumerable_Reference")] | ||
[Benchmark(Baseline = true)] | ||
public bool Linq_Enumerable_Reference() => | ||
System.Linq.Enumerable.Contains(enumerableReference, Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Collection_Reference")] | ||
[Benchmark(Baseline = true)] | ||
public bool Linq_Collection_Reference() => | ||
System.Linq.Enumerable.Contains(collectionReference, Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("List_Reference")] | ||
[Benchmark(Baseline = true)] | ||
public bool Linq_List_Reference() => | ||
System.Linq.Enumerable.Contains(listReference, Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Array")] | ||
[Benchmark] | ||
public bool LinqFaster_Array() => | ||
array.ContainsF(Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Array")] | ||
[Benchmark] | ||
public bool Hyperlinq_Array() => | ||
array.Contains(Count - 1, EqualityComparer<int>.Default); | ||
|
||
#if SPAN_SUPPORTED | ||
[BenchmarkCategory("Array")] | ||
[Benchmark] | ||
public bool Hyperlinq_Span() => | ||
array.AsSpan().Contains(Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Array")] | ||
[Benchmark] | ||
public bool Hyperlinq_Memory() => | ||
memory.Contains(Count - 1, EqualityComparer<int>.Default); | ||
#endif | ||
|
||
[BenchmarkCategory("Enumerable_Value")] | ||
[Benchmark] | ||
public bool Hyperlinq_Enumerable_Value() => | ||
Enumerable.AsValueEnumerable<TestEnumerable.Enumerable, TestEnumerable.Enumerable.Enumerator, int>(enumerableValue, enumerable => enumerable.GetEnumerator()) | ||
.Contains(Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Collection_Value")] | ||
[Benchmark] | ||
public bool Hyperlinq_Collection_Value() => | ||
ReadOnlyCollection.AsValueEnumerable<TestCollection.Enumerable, TestCollection.Enumerable.Enumerator, int>(collectionValue, enumerable => enumerable.GetEnumerator()) | ||
.Contains(Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("List_Value")] | ||
[Benchmark] | ||
public bool Hyperlinq_List_Value() => | ||
ReadOnlyList.AsValueEnumerable<int>(listValue) | ||
.Contains(Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Enumerable_Reference")] | ||
[Benchmark] | ||
public bool Hyperlinq_Enumerable_Reference() => | ||
enumerableReference | ||
.AsValueEnumerable() | ||
.Contains(Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("Collection_Reference")] | ||
[Benchmark] | ||
public bool Hyperlinq_Collection_Reference() => | ||
collectionReference | ||
.AsValueEnumerable() | ||
.Contains(Count - 1, EqualityComparer<int>.Default); | ||
|
||
[BenchmarkCategory("List_Reference")] | ||
[Benchmark] | ||
public bool Hyperlinq_List_Reference() => | ||
listReference | ||
.AsValueEnumerable() | ||
.Contains(Count - 1, EqualityComparer<int>.Default); | ||
} | ||
} |
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
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
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
Oops, something went wrong.