-
Notifications
You must be signed in to change notification settings - Fork 35
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
[Enhancement] Can these API's also work on IReadOnlyList<T> #15
Comments
I don't think there would be any performance difference since IEnumerable would still be happening behind the scenes. |
|
If you want, set up a little microbenchmark, doing sum or max or something with an Ilist with linq for using a for loop and the accessor. If there is a substantial difference I could think about supporting IList. |
I took this up because I was interested in the profile. Of course the results will depend on the underlying implementation, but I was curious if the single interface call to LegacyJIT Results:BenchmarkDotNet=v0.11.5, OS=Windows 10.0.17134.765 (1803/April2018Update/Redstone4)
Intel Core i7-6820HQ CPU 2.70GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
[Host] : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3416.0
ShortRun : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3416.0
Job=ShortRun IterationCount=3 LaunchCount=1
WarmupCount=3
RyuJIT x64 Results:BenchmarkDotNet=v0.11.5, OS=Windows 10.0.17134.765 (1803/April2018Update/Redstone4)
Intel Core i7-6820HQ CPU 2.70GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
[Host] : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3416.0
ShortRun : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3416.0
Job=ShortRun Jit=RyuJit Platform=X64
IterationCount=3 LaunchCount=1 WarmupCount=3
Code, for validity testing:(Requires benchmarkdotnet nuget package to be added) namespace ListVsEnumerable
{
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
public class Program
{
private static void Main(string[] args)
{
BenchmarkRunner.Run<Program>(
DefaultConfig.Instance
.With(Job.ShortRun));
// .With(Job.ShortRun.With(Jit.RyuJit).With(Platform.X64)));
}
private const int ListLength = 1000;
private static readonly IList<int> list = Enumerable.Range(0, ListLength).ToList();
[Benchmark]
public void EnumerateEnumerable()
{
foreach (var item in list) { }
}
[Benchmark]
public void EnumerateList()
{
int count = list.Count;
for (int i = 0; i < count; i++)
{
var item = list[i];
}
}
[Benchmark]
public long SumEnumerable()
{
long sum = 0;
foreach (var item in list)
{
sum += item;
}
return sum;
}
[Benchmark]
public long SumList()
{
int count = list.Count;
long sum = 0;
for (int i = 0; i < count; i++)
{
var item = list[i];
sum += item;
}
return sum;
}
}
} Do note that this has to take advantage of the optimization of pulling
This slightly suggests that perhaps |
Note: this is what I have found in the past as well. |
yeah the bounds check probably isn’t getting eliminated when working with an enunerable plus count has function call overhead here probably. its a misoptimization with arrays and lists but good with IList. kinda silly! anyway this would be valuable to add support for, its easy work but a lot of it. if people want to call a file they want to tackle here to help out that would be great. |
It doesn't contradict, since that's not on IList. The compiler only does this when the type can be KNOWN to be an array (this is why providing overrides for Arrays themselves can be insanely beneficial) |
Currently doing something for the SumF's |
- Add SumF API's to redirect IList's to their base types
Currently doing AverageF's |
- Done for Aggregate - Add All Span types - Add ReadOnlySpan - Reduce code in SumList
- Fix copy paste error - Add better intellisense text
First's then found this: #22 |
Changed to |
…ReadOnlyList<T> - Change over to IReadOnlyList
Doing LastF's |
…dOnlyList<T> - Implement LastF's the same way as FirstF's
Doing MaxF's |
…ReadOnlyList<T> - Use types instead of vars - Breakout Max Benchmarks - Breakout MaxF API's for different types into seperate files
Doing MinF's |
…ReadOnlyList<T> - Split MinF's out into seperate files - Change to NameOf for Selector parameter
Doing WhereSumF's |
… on IReadOnlyList<T> - Replacement to use nameof for source - Split more benchmarks out into seperate relevant files
|
No description provided.
The text was updated successfully, but these errors were encountered: