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

Batch: IList<> implementation #435

Merged
merged 4 commits into from
May 21, 2023
Merged

Batch: IList<> implementation #435

merged 4 commits into from
May 21, 2023

Conversation

viceroypenguin
Copy link
Owner

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

Fixes #433

// * 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
BatchCount Syste(...)nt32] [47] 10000 9.218 ns 0.0719 ns 0.0673 ns 0.0025 0.0000 32 B
BatchCount Syste(...)nt32] [62] 10000 84,466.111 ns 288.4135 ns 269.7822 ns - - 272 B
BatchCopyTo Syste(...)nt32] [47] 10000 20,873.986 ns 139.9441 ns 124.0568 ns 4.4556 0.7019 56104 B
BatchCopyTo Syste(...)nt32] [62] 10000 84,675.289 ns 311.1713 ns 291.0698 ns 0.6104 0.1221 8760 B
BatchElementAt Syste(...)nt32] [47] 10000 51.323 ns 0.2610 ns 0.2441 ns 0.0108 0.0001 136 B
BatchElementAt Syste(...)nt32] [62] 10000 65,809.909 ns 415.9993 ns 389.1260 ns - - 272 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 BatchCount(IEnumerable<int> source1, int N)
{
	_ = source1.Batch(20).Count();
}

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

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void BatchElementAt(IEnumerable<int> source1, int N)
{
	_ = source1.Batch(20).ElementAt(400);
}

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

codecov bot commented May 21, 2023

Codecov Report

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

Comparison is base (4caec0f) 88.24% compared to head (6269731) 88.28%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
+ Coverage   88.24%   88.28%   +0.04%     
==========================================
  Files         244      245       +1     
  Lines        7692     7719      +27     
  Branches     1771     1777       +6     
==========================================
+ Hits         6788     6815      +27     
  Misses        462      462              
  Partials      442      442              
Impacted Files Coverage Δ
Source/SuperLinq/Batch.Buffered.cs 100.00% <100.00%> (ø)
Source/SuperLinq/Batch.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 4ea263a into master May 21, 2023
@viceroypenguin viceroypenguin deleted the batch-ilist branch May 21, 2023 14:45
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 Batch
1 participant