-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add Benchmarks #656
Open
viceroypenguin
wants to merge
3
commits into
master
Choose a base branch
from
benchmarks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Benchmarks #656
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[*.cs] | ||
|
||
dotnet_diagnostic.CA1062.severity = none | ||
dotnet_diagnostic.CA1515.severity = none | ||
dotnet_diagnostic.CA1707.severity = none # CA1707: Identifiers should not contain underscores | ||
dotnet_diagnostic.CA1861.severity = none # CA1861: Avoid constant arrays as arguments | ||
dotnet_diagnostic.CA2201.severity = none # CA2201: Do not raise reserved exception types | ||
|
||
dotnet_diagnostic.IDE0022.severity = none # IDE0022: Use expression body for methods | ||
|
||
# XML Documentation | ||
dotnet_diagnostic.CS1573.severity = none # CS1573: Missing XML comment for parameter | ||
dotnet_diagnostic.CS1591.severity = none # CS1591: Missing XML comment for publicly visible type or member | ||
dotnet_diagnostic.CS1712.severity = none # CS1712: Type parameter has no matching typeparam tag in the XML comment (but other type parameters do) | ||
|
||
dotnet_diagnostic.MA0046.severity = none | ||
dotnet_diagnostic.MA0053.severity = none |
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,130 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace SuperLinq.Benchmarks; | ||
|
||
[SuppressMessage("Design", "CA1052:Static holder types should be Static or NotInheritable")] | ||
public class TestDataBenchmark | ||
{ | ||
public static IEnumerable<LinqTestData> NoSpecialization() | ||
{ | ||
yield return LinqTestData.s_iEnumerable; | ||
} | ||
|
||
public static IEnumerable<LinqTestData> CollectionSpecialization() | ||
{ | ||
yield return LinqTestData.s_iEnumerable; | ||
yield return LinqTestData.s_iCollection; | ||
} | ||
|
||
public static IEnumerable<LinqTestData> CountSpecialization() | ||
{ | ||
yield return LinqTestData.s_iEnumerable; | ||
yield return LinqTestData.s_range; | ||
yield return LinqTestData.s_iCollection; | ||
} | ||
|
||
public static IEnumerable<LinqTestData> ListSpecialization() | ||
{ | ||
yield return LinqTestData.s_iEnumerable; | ||
yield return LinqTestData.s_array; | ||
yield return LinqTestData.s_list; | ||
yield return LinqTestData.s_iList; | ||
} | ||
|
||
public static IEnumerable<LinqTestData> FullSpecialization() | ||
{ | ||
yield return LinqTestData.s_iEnumerable; | ||
yield return LinqTestData.s_iCollection; | ||
yield return LinqTestData.s_array; | ||
yield return LinqTestData.s_list; | ||
yield return LinqTestData.s_iList; | ||
} | ||
} | ||
|
||
public sealed class LinqTestData | ||
{ | ||
// this field is a const (not instance field) to avoid creating closures in tested LINQ | ||
internal const int Size = 100; | ||
|
||
private static readonly int[] s_arrayOf100Integers = Enumerable.Range(0, Size).ToArray(); | ||
|
||
internal static readonly LinqTestData s_array = new(s_arrayOf100Integers); | ||
internal static readonly LinqTestData s_list = new(new List<int>(s_arrayOf100Integers)); | ||
internal static readonly LinqTestData s_range = new(Enumerable.Range(0, Size)); | ||
internal static readonly LinqTestData s_iEnumerable = new(new IEnumerableWrapper<int>(s_arrayOf100Integers)); | ||
internal static readonly LinqTestData s_iList = new(new IListWrapper<int>(s_arrayOf100Integers)); | ||
internal static readonly LinqTestData s_iCollection = new(new ICollectionWrapper<int>(s_arrayOf100Integers)); | ||
internal static readonly LinqTestData s_iOrderedEnumerable = new(s_arrayOf100Integers.OrderBy(i => i)); // OrderBy() returns IOrderedEnumerable (OrderedEnumerable is internal) | ||
|
||
private LinqTestData(IEnumerable<int> collection) => Collection = collection; | ||
|
||
internal IEnumerable<int> Collection { get; } | ||
|
||
public override string ToString() | ||
{ | ||
if (ReferenceEquals(this, s_range)) // RangeIterator is a private type | ||
return "Range"; | ||
|
||
return Collection switch | ||
{ | ||
int[] => "Array", | ||
List<int> => "List", | ||
IList<int> => "IList", | ||
ICollection<int> => "ICollection", | ||
IOrderedEnumerable<int> => "IOrderedEnumerable", | ||
_ => "IEnumerable", | ||
}; | ||
} | ||
|
||
private sealed class IEnumerableWrapper<T>(T[] array) : IEnumerable<T> | ||
{ | ||
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>)array).GetEnumerator(); | ||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => ((IEnumerable<T>)array).GetEnumerator(); | ||
} | ||
|
||
private sealed class ICollectionWrapper<T>(T[] array) : ICollection<T> | ||
{ | ||
private readonly T[] _array = array; | ||
|
||
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>)_array).GetEnumerator(); | ||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => ((IEnumerable<T>)_array).GetEnumerator(); | ||
|
||
public int Count => _array.Length; | ||
public bool IsReadOnly => true; | ||
public bool Contains(T item) => Array.IndexOf(_array, item) >= 0; | ||
public void CopyTo(T[] array, int arrayIndex) => _array.CopyTo(array, arrayIndex); | ||
|
||
public void Add(T item) => throw new NotSupportedException(); | ||
public void Clear() => throw new NotSupportedException(); | ||
public bool Remove(T item) => throw new NotSupportedException(); | ||
} | ||
|
||
private sealed class IListWrapper<T>(T[] array) : IList<T> | ||
{ | ||
private readonly T[] _array = array; | ||
|
||
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>)_array).GetEnumerator(); | ||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => ((IEnumerable<T>)_array).GetEnumerator(); | ||
|
||
public int Count => _array.Length; | ||
public bool IsReadOnly => true; | ||
public T this[int index] | ||
{ | ||
get => _array[index]; | ||
set => throw new NotSupportedException(); | ||
} | ||
public bool Contains(T item) => Array.IndexOf(_array, item) >= 0; | ||
public void CopyTo(T[] array, int arrayIndex) => _array.CopyTo(array, arrayIndex); | ||
public int IndexOf(T item) => Array.IndexOf(_array, item); | ||
|
||
public void Add(T item) => throw new NotSupportedException(); | ||
public void Clear() => throw new NotSupportedException(); | ||
public bool Remove(T item) => throw new NotSupportedException(); | ||
public void Insert(int index, T item) => throw new NotSupportedException(); | ||
public void RemoveAt(int index) => throw new NotSupportedException(); | ||
} | ||
} |
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,11 @@ | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Diagnosers; | ||
using BenchmarkDotNet.Running; | ||
|
||
BenchmarkSwitcher | ||
.FromAssembly(typeof(Program).Assembly) | ||
.Run( | ||
args, | ||
DefaultConfig.Instance | ||
.AddDiagnoser(MemoryDiagnoser.Default) | ||
); |
17 changes: 17 additions & 0 deletions
17
Benchmarks/SuperLinq.Benchmarks/SuperLinq.Benchmarks.csproj
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../Source/SuperLinq.Async/SuperLinq.Async.csproj" /> | ||
<ProjectReference Include="../../Source/SuperLinq/SuperLinq.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
37 changes: 37 additions & 0 deletions
37
Benchmarks/SuperLinq.Benchmarks/Sync/FilteringBenchmarks.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,37 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
|
||
namespace SuperLinq.Benchmarks.Sync; | ||
|
||
public class FilteringBenchmarks : TestDataBenchmark | ||
{ | ||
private readonly Consumer _consumer = new(); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(NoSpecialization))] | ||
public void Choose(LinqTestData testData) => | ||
testData.Collection | ||
.Choose(x => (false, x)) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(NoSpecialization))] | ||
public void Where(LinqTestData testData) => | ||
testData.Collection | ||
.Where(testData.Collection.Select(x => true)) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(NoSpecialization))] | ||
public void WhereLead(LinqTestData testData) => | ||
testData.Collection | ||
.WhereLead(1, (a, b) => true) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(NoSpecialization))] | ||
public void WhereLag(LinqTestData testData) => | ||
testData.Collection | ||
.WhereLag(1, (a, b) => true) | ||
.Consume(_consumer); | ||
} |
87 changes: 87 additions & 0 deletions
87
Benchmarks/SuperLinq.Benchmarks/Sync/ProjectionBenchmarks.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,87 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
|
||
namespace SuperLinq.Benchmarks.Sync; | ||
|
||
[BenchmarkCategory("Projection")] | ||
public class ProjectionBenchmarks : TestDataBenchmark | ||
{ | ||
private readonly Consumer _consumer = new(); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(ListSpecialization))] | ||
public void EquiZip(LinqTestData testData) => | ||
testData.Collection | ||
.EquiZip(testData.Collection) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(ListSpecialization))] | ||
public void ZipShortest(LinqTestData testData) => | ||
testData.Collection | ||
.ZipShortest(testData.Collection) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(ListSpecialization))] | ||
public void ZipLongest(LinqTestData testData) => | ||
testData.Collection | ||
.ZipLongest(testData.Collection) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(CountSpecialization))] | ||
public void CountDown(LinqTestData testData) => | ||
testData.Collection | ||
.CountDown(5) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(CountSpecialization))] | ||
public void TagFirstLast(LinqTestData testData) => | ||
testData.Collection | ||
.TagFirstLast() | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(ListSpecialization))] | ||
public void Index(LinqTestData testData) => | ||
testData.Collection | ||
.Index() | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(NoSpecialization))] | ||
public void IndexBy(LinqTestData testData) => | ||
testData.Collection | ||
.IndexBy(x => x % 10) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(ListSpecialization))] | ||
public void Lag(LinqTestData testData) => | ||
testData.Collection | ||
.Lag(1) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(ListSpecialization))] | ||
public void Lead(LinqTestData testData) => | ||
testData.Collection | ||
.Lead(1) | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(NoSpecialization))] | ||
public void Rank(LinqTestData testData) => | ||
testData.Collection | ||
.Rank() | ||
.Consume(_consumer); | ||
|
||
[Benchmark] | ||
[ArgumentsSource(nameof(ListSpecialization))] | ||
public void ZipMap(LinqTestData testData) => | ||
testData.Collection | ||
.ZipMap(_ => true) | ||
.Consume(_consumer); | ||
} |
Oops, something went wrong.
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.
Adding a justification would help external contributors understand why it's important to suppress this particular analysis rule.