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

Replace: IList<> implementation #454

Merged
merged 3 commits into from
May 24, 2023
Merged

Replace: IList<> implementation #454

merged 3 commits into from
May 24, 2023

Conversation

viceroypenguin
Copy link
Owner

This PR adds an IList<> implementation of Replace, which improves memory usage and performance. Also, a bug in Replace using ^x indices is fixed.

Fixes #437

// * 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
ReplaceCount Syste(...)nt32] [47] 10000 8.273 ns 0.1330 ns 0.1244 ns 0.0025 0.0000 32 B
ReplaceCount Syste(...)nt32] [62] 10000 96,727.650 ns 662.4417 ns 619.6484 ns - - 168 B
ReplaceCopyTo Syste(...)nt32] [47] 10000 1,987.191 ns 27.4487 ns 24.3326 ns 3.1815 0.0038 40056 B
ReplaceCopyTo Syste(...)nt32] [62] 10000 118,530.481 ns 818.7933 ns 765.8998 ns 8.4229 0.8545 106352 B
ReplaceElementAt Syste(...)nt32] [47] 10000 15.284 ns 0.2302 ns 0.2154 ns 0.0025 0.0000 32 B
ReplaceElementAt Syste(...)nt32] [62] 10000 74,150.606 ns 270.0764 ns 225.5261 ns - - 168 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 ReplaceCount(IEnumerable<int> source1, int N)
{
	_ = source1.Replace(20, -30).Count();
}

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

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

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

codecov bot commented May 24, 2023

Codecov Report

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

Comparison is base (6aaff5c) 91.20% compared to head (01e5441) 91.23%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #454      +/-   ##
==========================================
+ Coverage   91.20%   91.23%   +0.02%     
==========================================
  Files         245      245              
  Lines        7770     7794      +24     
  Branches     1592     1598       +6     
==========================================
+ Hits         7087     7111      +24     
  Misses        464      464              
  Partials      219      219              
Impacted Files Coverage Δ
Source/SuperLinq/Replace.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 479a773 into master May 24, 2023
@viceroypenguin viceroypenguin deleted the replace-ilist branch May 24, 2023 13:29
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 Replace
1 participant