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

ScanRight: ICollection<> implementation #387

Merged
merged 4 commits into from
May 7, 2023

Conversation

viceroypenguin
Copy link
Owner

@viceroypenguin viceroypenguin commented May 7, 2023

This PR adds an ICollection<> implementation of the ScanRight operator.

Fixes #386

// * 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
ScanRightCount Syste(...)nt32] [50] 10000 9.686 ns 0.1100 ns 0.1029 ns 0.0025 0.0000 32 B
ScanRightCount Syste(...)nt32] [47] 10000 10.246 ns 0.0946 ns 0.0885 ns 0.0025 0.0000 32 B
ScanRightCount Syste(...)nt32] [70] 10000 88,253.740 ns 307.4105 ns 256.7017 ns 6.3477 0.7324 80200 B
ScanRightCopyTo Syste(...)nt32] [50] 10000 38,673.586 ns 158.7586 ns 123.9483 ns 3.1738 0.0610 40056 B
ScanRightCopyTo Syste(...)nt32] [47] 10000 29,826.876 ns 206.6878 ns 183.2234 ns 3.1738 0.0305 40056 B
ScanRightCopyTo Syste(...)nt32] [70] 10000 101,039.215 ns 472.9422 ns 419.2510 ns 14.7705 1.0986 186384 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).ToList().Select(SuperEnumerable.Identity),
			i,
		};
		yield return new object[]
		{
			Enumerable.Range(1, i).ToHashSet(),
			i,
		};
		yield return new object[]
		{
			Enumerable.Range(1, i).ToList(),
			i,
		};
	}
}

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void ScanRightCount(IEnumerable<int> source, int N)
{
	_ = source.ScanRight((a, b) => a + b).Count();
}

[Benchmark]
[ArgumentsSource(nameof(EnumerableArguments))]
public void ScanRightCopyTo(IEnumerable<int> source, int N)
{
	_ = source.ScanRight((a, b) => a + b).ToArray();
}

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

codecov bot commented May 7, 2023

Codecov Report

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

Comparison is base (244f777) 87.44% compared to head (56a51cb) 87.52%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #387      +/-   ##
==========================================
+ Coverage   87.44%   87.52%   +0.08%     
==========================================
  Files         239      239              
  Lines        7207     7239      +32     
  Branches     1677     1681       +4     
==========================================
+ Hits         6302     6336      +34     
+ Misses        464      462       -2     
  Partials      441      441              
Impacted Files Coverage Δ
Source/SuperLinq/Do.cs 97.67% <ø> (ø)
Source/SuperLinq/FillBackward.cs 98.00% <ø> (ø)
Source/SuperLinq/FillForward.cs 100.00% <ø> (ø)
Source/SuperLinq/Interleave.cs 100.00% <ø> (ø)
Source/SuperLinq/Rank.cs 100.00% <ø> (ø)
Source/SuperLinq/Scan.cs 100.00% <ø> (ø)
Source/SuperLinq/ScanRight.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 changed the title Scanright icollection ScanRight: ICollection<> implementation May 7, 2023
@viceroypenguin viceroypenguin enabled auto-merge (squash) May 7, 2023 02:01
@viceroypenguin viceroypenguin merged commit d6a3261 into master May 7, 2023
@viceroypenguin viceroypenguin deleted the scanright-icollection branch May 7, 2023 02:08
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.

ICollection<T> version of ScanRight
1 participant