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

Lag: IList<> implementation #404

Merged
merged 3 commits into from
May 10, 2023
Merged

Lag: IList<> implementation #404

merged 3 commits into from
May 10, 2023

Conversation

viceroypenguin
Copy link
Owner

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

Fixes #403

// * 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
LagCount Syste(...)nt32] [47] 10000 9.776 ns 0.1670 ns 0.1394 ns 0.0032 0.0000 40 B
LagCount Syste(...)nt32] [62] 10000 127,925.439 ns 925.8349 ns 773.1141 ns - - 464 B
LagCopyTo Syste(...)nt32] [47] 10000 84,319.089 ns 448.5254 ns 419.5509 ns 6.3477 1.0986 80112 B
LagCopyTo Syste(...)nt32] [62] 10000 159,364.525 ns 3,112.8400 ns 3,057.2251 ns 16.8457 2.9297 212200 B
LagElementAt Syste(...)nt32] [47] 10000 16.877 ns 0.0723 ns 0.0641 ns 0.0032 0.0000 40 B
LagElementAt Syste(...)nt32] [62] 10000 101,622.887 ns 906.5200 ns 847.9594 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 LagCount(IEnumerable<int> source, int N)
{
	_ = source.Lag(50).Count();
}

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

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

Comparison is base (8552236) 87.72% compared to head (dee4505) 87.77%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
+ Coverage   87.72%   87.77%   +0.04%     
==========================================
  Files         239      239              
  Lines        7357     7370      +13     
  Branches     1701     1702       +1     
==========================================
+ Hits         6454     6469      +15     
+ Misses        463      461       -2     
  Partials      440      440              
Impacted Files Coverage Δ
Source/SuperLinq/Lag.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 a820ef0 into master May 10, 2023
@viceroypenguin viceroypenguin deleted the lag-ilist branch May 10, 2023 02:41
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 Lag
1 participant