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

ZipShortest: IList<> implementation #415

Merged
merged 1 commit into from
May 11, 2023
Merged

Conversation

viceroypenguin
Copy link
Owner

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

Fixes #414

// * 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.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
ZipShortestCount Syste(...)nt32] [47] Syste(...)nt32] [47] 20000 16.15 ns 0.191 ns 0.179 ns 0.0032 0.0000 40 B
ZipShortestCount Syste(...)nt32] [62] Syste(...)nt32] [62] 20000 196,853.97 ns 906.537 ns 847.975 ns - - 288 B
ZipShortestCopyTo Syste(...)nt32] [47] Syste(...)nt32] [47] 20000 85,644.68 ns 568.697 ns 531.960 ns 6.3477 1.0986 80112 B
ZipShortestCopyTo Syste(...)nt32] [62] Syste(...)nt32] [62] 20000 225,560.32 ns 1,250.051 ns 1,169.299 ns 16.8457 2.9297 212024 B
ZipShortestElementAt Syste(...)nt32] [47] Syste(...)nt32] [47] 20000 25.36 ns 0.177 ns 0.165 ns 0.0032 0.0000 40 B
ZipShortestElementAt Syste(...)nt32] [62] Syste(...)nt32] [62] 20000 153,127.18 ns 891.006 ns 833.448 ns - - 288 B
Code
#load "BenchmarkDotNet"

void Main()
{
	RunBenchmark();
}

public IEnumerable<object[]> EnumerableArguments()
{
	foreach (var i in new[] { 20_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 ZipShortestCount(IEnumerable<int> source1, IEnumerable<int> source2, int N)
{
	_ = source1.ZipShortest(source2).Count();
}

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

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

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

codecov bot commented May 11, 2023

Codecov Report

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

Comparison is base (d147954) 87.90% compared to head (e70f363) 87.98%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #415      +/-   ##
==========================================
+ Coverage   87.90%   87.98%   +0.07%     
==========================================
  Files         239      239              
  Lines        7441     7489      +48     
  Branches     1716     1722       +6     
==========================================
+ Hits         6541     6589      +48     
  Misses        462      462              
  Partials      438      438              
Impacted Files Coverage Δ
...tor/SuperLinq.Generator.Generator/ZipShortest.g.cs 100.00% <100.00%> (ø)
Source/SuperLinq/SuperEnumerable.cs 100.00% <100.00%> (ø)

☔ 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 501b5a7 into master May 11, 2023
@viceroypenguin viceroypenguin deleted the zipshortest-ilist branch May 11, 2023 14:36
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 ZipShortest
1 participant