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

TagFirstLast: IList<> implementation #408

Merged
merged 1 commit into from
May 10, 2023
Merged

Conversation

viceroypenguin
Copy link
Owner

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

Fixes #407

// * 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
TagFirstLastCount Syste(...)nt32] [47] 10000 10.04 ns 0.092 ns 0.086 ns 0.0025 0.0000 32 B
TagFirstLastCount Syste(...)nt32] [62] 10000 107,083.41 ns 252.544 ns 223.874 ns - - 168 B
TagFirstLastCopyTo Syste(...)nt32] [47] 10000 78,637.78 ns 646.245 ns 604.498 ns 6.3477 1.0986 80104 B
TagFirstLastCopyTo Syste(...)nt32] [62] 10000 132,709.80 ns 836.973 ns 782.906 ns 16.6016 2.1973 211904 B
TagFirstLastElementAt Syste(...)nt32] [47] 10000 18.74 ns 0.122 ns 0.115 ns 0.0025 0.0000 32 B
TagFirstLastElementAt Syste(...)nt32] [62] 10000 84,293.48 ns 353.597 ns 330.755 ns - - 168 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 TagFirstLastCount(IEnumerable<int> source, int N)
{
	_ = source.TagFirstLast().Count();
}

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

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

Comparison is base (968455a) 87.77% compared to head (dc1497b) 87.80%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #408      +/-   ##
==========================================
+ Coverage   87.77%   87.80%   +0.03%     
==========================================
  Files         239      239              
  Lines        7385     7404      +19     
  Branches     1703     1707       +4     
==========================================
+ Hits         6482     6501      +19     
  Misses        463      463              
  Partials      440      440              
Impacted Files Coverage Δ
Source/SuperLinq/TagFirstLast.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 0340757 into master May 10, 2023
@viceroypenguin viceroypenguin deleted the tagfirstlast-ilist branch May 10, 2023 17:07
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 TagFirstLast
1 participant