Skip to content
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

Exclude: IList<> implementation #448

Merged
merged 1 commit into from
May 22, 2023
Merged

Exclude: IList<> implementation #448

merged 1 commit into from
May 22, 2023

Conversation

viceroypenguin
Copy link
Owner

This PR adds an IList<> implementation for Exclude, which improves memory usage and performance.

Fixes #447

// * Summary *

BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1702/22H2/2022Update/SunValley2)
12th Gen Intel Core i7-12700H, 1 CPU, 20 logical and 14 physical cores
.NET SDK=8.0.100-preview.4.23260.5
  [Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
Method source1 N Mean Error StdDev Gen0 Gen1 Allocated
ExcludeCount Syste(...)nt32] [47] 10000 11.31 ns 0.208 ns 0.184 ns 0.0025 0.0000 32 B
ExcludeCount Syste(...)nt32] [62] 10000 96,426.59 ns 530.348 ns 470.140 ns - - 176 B
ExcludeCopyTo Syste(...)nt32] [47] 10000 50,851.92 ns 245.606 ns 205.092 ns 3.1738 0.0610 40024 B
ExcludeCopyTo Syste(...)nt32] [62] 10000 111,872.16 ns 668.736 ns 592.817 ns 8.4229 0.9766 106280 B
ExcludeElementAt Syste(...)nt32] [47] 10000 16.67 ns 0.176 ns 0.165 ns 0.0025 0.0000 32 B
ExcludeElementAt Syste(...)nt32] [62] 10000 75,288.59 ns 470.657 ns 393.020 ns - - 176 B
Code
#load "BenchmarkDotNet"

void Main()
{
	RunBenchmark();
}

public IEnumerable<object[]> EnumerableArguments()
{
	foreach (var i in new[] { 10_000, })
	{
		yield return new object[]
		{
			Enumerable.Range(1, i).Where(_ => true),
			i,
		};
		yield return new object[]
		{
			Enumerable.Range(1, i).ToList(),
			i,
		};
	}
}

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void ExcludeCount(IEnumerable<int> source1, int N)
{
	_ = source1.Exclude(20, 20).Count();
}

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void ExcludeCopyTo(IEnumerable<int> source1, int N)
{
	_ = source1.Exclude(20, 20).ToArray();
}

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void ExcludeElementAt(IEnumerable<int> source1, int N)
{
	_ = source1.Exclude(20, 20).ElementAt(8_000);
}

@viceroypenguin viceroypenguin added this to the 5.1.0 milestone May 22, 2023
@codecov
Copy link

codecov bot commented May 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05 🎉

Comparison is base (e636102) 91.15% compared to head (e967b79) 91.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #448      +/-   ##
==========================================
+ Coverage   91.15%   91.21%   +0.05%     
==========================================
  Files         245      245              
  Lines        7723     7741      +18     
  Branches     1583     1588       +5     
==========================================
+ Hits         7040     7061      +21     
+ Misses        464      461       -3     
  Partials      219      219              
Impacted Files Coverage Δ
Source/SuperLinq/Exclude.cs 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@viceroypenguin viceroypenguin merged commit 260308c into master May 22, 2023
@viceroypenguin viceroypenguin deleted the exclude-ilist branch May 22, 2023 23:23
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.

IList<> version of Exclude
1 participant