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

Lead: IList<> implementation #406

Merged
merged 2 commits into from
May 10, 2023
Merged

Lead: IList<> implementation #406

merged 2 commits into from
May 10, 2023

Conversation

viceroypenguin
Copy link
Owner

This PR adds an IList<> implementation of Lead, which reduces memory usage and improves performance.

Fixes #405

// * 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 source N Mean Error StdDev Gen0 Gen1 Allocated
LeadCount Syste(...)nt32] [47] 10000 11.11 ns 0.101 ns 0.090 ns 0.0032 0.0000 40 B
LeadCount Syste(...)nt32] [62] 10000 130,990.59 ns 679.288 ns 635.406 ns - - 464 B
LeadCopyTo Syste(...)nt32] [47] 10000 82,063.31 ns 416.850 ns 389.922 ns 6.3477 1.0986 80120 B
LeadCopyTo Syste(...)nt32] [62] 10000 150,546.04 ns 845.796 ns 791.158 ns 16.8457 2.9297 212200 B
LeadElementAt Syste(...)nt32] [47] 10000 18.10 ns 0.381 ns 0.509 ns 0.0032 0.0000 40 B
LeadElementAt Syste(...)nt32] [62] 10000 101,688.96 ns 928.388 ns 822.991 ns - - 464 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 LeadCount(IEnumerable<int> source, int N)
{
	_ = source.Lead(50).Count();
}

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void LeadCopyTo(IEnumerable<int> source, int N)
{
	_ = source.Lead(50).ToArray();
}

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void LeadElementAt(IEnumerable<int> source, int N)
{
	_ = source.Lead(50).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.01 🎉

Comparison is base (a820ef0) 87.74% compared to head (de60975) 87.76%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #406      +/-   ##
==========================================
+ Coverage   87.74%   87.76%   +0.01%     
==========================================
  Files         239      239              
  Lines        7370     7386      +16     
  Branches     1702     1703       +1     
==========================================
+ Hits         6467     6482      +15     
- Misses        463      464       +1     
  Partials      440      440              
Impacted Files Coverage Δ
Source/SuperLinq/Lead.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 968455a into master May 10, 2023
@viceroypenguin viceroypenguin deleted the lead-ilist branch May 10, 2023 16:20
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 Lead
1 participant