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

Sequence: IList<> implementation #417

Merged
merged 4 commits into from
May 12, 2023
Merged

Sequence: IList<> implementation #417

merged 4 commits into from
May 12, 2023

Conversation

viceroypenguin
Copy link
Owner

This PR changes Sequence and Range to use an IList<> implementation to improve performance.

Fixes #416

// * 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.3.23178.7
  [Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
Method Mean Error StdDev Gen0 Gen1 Allocated
SequenceListCount 6.512 ns 0.0806 ns 0.0754 ns 0.0025 0.0000 32 B
SequenceEnumerableCount 26,418.452 ns 119.2042 ns 111.5037 ns - - 64 B
SequenceListCopyTo 41,894.557 ns 236.9645 ns 210.0628 ns 3.1738 0.3662 40112 B
SequenceEnumerableCopyTo 43,789.558 ns 320.3513 ns 283.9831 ns 8.4229 0.8545 106256 B
SequenceListElementAt 9.782 ns 0.1094 ns 0.0970 ns 0.0025 0.0000 32 B
SequenceEnumerableElementAt 16,407.080 ns 151.0511 ns 141.2933 ns - - 64 B
Code
#load "BenchmarkDotNet"

void Main()
{
	RunBenchmark();
}

[Benchmark]
public void SequenceListCount()
{
	_ = SuperEnumerable.Sequence(0, 10_000, 1).Count();
}

[Benchmark]
public void SequenceListCopyTo()
{
	_ = SuperEnumerable.Sequence(0, 10_000, 1).ToArray();
}

[Benchmark]
public void SequenceListElementAt()
{
	_ = SuperEnumerable.Sequence(0, 10_000, 1).ElementAt(8_000);
}

[Benchmark]
public void SequenceEnumerableCount()
{
	_ = Sequence(0, 10_000, 1).Count();
}

[Benchmark]
public void SequenceEnumerableCopyTo()
{
	_ = Sequence(0, 10_000, 1).ToArray();
}

[Benchmark]
public void SequenceEnumerableElementAt()
{
	_ = Sequence(0, 10_000, 1).ElementAt(8_000);
}

static IEnumerable<int> Sequence(int start, int stop, int step)
{
	long current = start;
	while (step >= 0
			? stop >= current
			: stop <= current)
	{
		yield return (int)current;
		current += step;
	}
}

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

codecov bot commented May 12, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (501b5a7) 88.00% compared to head (fa8072b) 88.01%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #417   +/-   ##
=======================================
  Coverage   88.00%   88.01%           
=======================================
  Files         239      239           
  Lines        7489     7498    +9     
  Branches     1722     1725    +3     
=======================================
+ Hits         6591     6599    +8     
- Misses        460      461    +1     
  Partials      438      438           
Impacted Files Coverage Δ
Source/SuperLinq/Sequence.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 8435865 into master May 12, 2023
@viceroypenguin viceroypenguin deleted the sequence-ilist branch May 12, 2023 17:52
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 Sequence
1 participant