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

ZipLongest: IList<> implementation #413

Merged
merged 3 commits into from
May 11, 2023
Merged

ZipLongest: IList<> implementation #413

merged 3 commits into from
May 11, 2023

Conversation

viceroypenguin
Copy link
Owner

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

Fixes #411

// * Summary *

BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1555/22H2/2022Update/SunValley2)
12th Gen Intel Core i7-12700H, 1 CPU, 20 logical and 14 physical cores
.NET SDK=8.0.100-preview.3.23178.7
  [Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
Method source1 source2 N Mean Error StdDev Gen0 Gen1 Allocated
ZipLongestCount Syste(...)nt32] [47] Syste(...)nt32] [47] 10000 15.97 ns 0.157 ns 0.131 ns 0.0032 0.0000 40 B
ZipLongestCount Syste(...)nt32] [62] Syste(...)nt32] [62] 10000 159,520.55 ns 667.403 ns 591.635 ns - - 296 B
ZipLongestCopyTo Syste(...)nt32] [47] Syste(...)nt32] [47] 10000 109,703.55 ns 577.051 ns 511.541 ns 6.3477 1.0986 80112 B
ZipLongestCopyTo Syste(...)nt32] [62] Syste(...)nt32] [62] 10000 187,554.54 ns 1,372.398 ns 1,283.742 ns 16.8457 2.9297 212032 B
ZipLongestElementAt Syste(...)nt32] [47] Syste(...)nt32] [47] 10000 26.30 ns 0.223 ns 0.197 ns 0.0032 0.0000 40 B
ZipLongestElementAt Syste(...)nt32] [62] Syste(...)nt32] [62] 10000 130,856.39 ns 813.885 ns 721.488 ns - - 296 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),
			Enumerable.Range(1, i / 2).Where(_ => true),
			i,
		};
		yield return new object[]
		{
			Enumerable.Range(1, i).ToList(),
			Enumerable.Range(1, i / 2).ToList(),
			i,
		};
	}
}

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

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

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

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

codecov bot commented May 10, 2023

Codecov Report

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

Comparison is base (0340757) 87.83% compared to head (cddcb81) 87.88%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #413      +/-   ##
==========================================
+ Coverage   87.83%   87.88%   +0.05%     
==========================================
  Files         239      239              
  Lines        7404     7452      +48     
  Branches     1707     1719      +12     
==========================================
+ Hits         6503     6549      +46     
- Misses        461      463       +2     
  Partials      440      440              
Impacted Files Coverage Δ
...ator/SuperLinq.Generator.Generator/ZipLongest.g.cs 100.00% <100.00%> (ø)
Source/SuperLinq/SuperEnumerable.cs 81.81% <100.00%> (+6.81%) ⬆️

... 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 ea91311 into master May 11, 2023
@viceroypenguin viceroypenguin deleted the ziplongest-ilist branch May 11, 2023 00:05
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 ZipLongest
1 participant