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

WindowRight: IList<> implementation #429

Merged
merged 1 commit into from
May 19, 2023
Merged

Conversation

viceroypenguin
Copy link
Owner

@viceroypenguin viceroypenguin commented May 19, 2023

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

Fixes #421

// * 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
WindowRightCount Syste(...)nt32] [47] 10000 9.368 ns 0.0775 ns 0.0725 ns 0.0025 0.0000 32 B
WindowRightCount Syste(...)nt32] [62] 10000 187,226.046 ns 1,752.2183 ns 1,463.1816 ns 82.7637 0.2441 1039456 B
WindowRightCopyTo Syste(...)nt32] [47] 10000 202,230.651 ns 3,443.8864 ns 2,875.8011 ns 89.1113 51.5137 1119392 B
WindowRightCopyTo Syste(...)nt32] [62] 10000 272,945.487 ns 4,690.4483 ns 5,213.4208 ns 99.6094 59.0820 1251192 B
WindowRightElementAt Syste(...)nt32] [47] 10000 43.971 ns 0.3483 ns 0.2908 ns 0.0108 0.0001 136 B
WindowRightElementAt Syste(...)nt32] [62] 10000 150,312.289 ns 1,117.5530 ns 990.6816 ns 66.1621 0.2441 831664 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 WindowRightCount(IEnumerable<int> source1, int N)
{
	_ = source1.WindowRight(20).Count();
}

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

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

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

codecov bot commented May 19, 2023

Codecov Report

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

Comparison is base (5de97e2) 88.13% compared to head (ed9b9bd) 88.19%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #429      +/-   ##
==========================================
+ Coverage   88.13%   88.19%   +0.06%     
==========================================
  Files         242      242              
  Lines        7568     7608      +40     
  Branches     1739     1746       +7     
==========================================
+ Hits         6670     6710      +40     
  Misses        460      460              
  Partials      438      438              
Impacted Files Coverage Δ
Source/SuperLinq/WindowRight.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 4122af6 into master May 19, 2023
@viceroypenguin viceroypenguin deleted the windowright-ilist branch May 19, 2023 01:28
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 WindowRight
1 participant