Skip to content

Commit e3c97cf

Browse files
committed
Cleanup
1 parent e78d541 commit e3c97cf

27 files changed

+74
-109
lines changed

Benchmarks/ArrayIterationBenchmarks.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ BenchmarkDotNet=v0.13.0.1555-nightly, OS=Windows 10.0.19043.1081 (21H1/May2021Up
1818
Intel Core i7-7567U CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 2 physical cores
1919
.NET SDK=6.0.100-preview.5.21302.13
2020
[Host] : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT
21-
Job-UGMGOQ : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT
21+
Job-SLIMHF : .NET 6.0.0 (6.0.21.30105), X64 RyuJIT
2222

2323
Runtime=.NET 6.0
2424

2525
```
26-
| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated |
27-
|--------------------- |-------- |-----------:|---------:|--------:|-------------:|--------:|------:|------:|------:|----------:|
28-
| Foreach | 1000000 | 411.6 μs | 3.58 μs | 2.99 μs | baseline | | - | - | - | - |
29-
| For | 1000000 | 410.3 μs | 1.57 μs | 1.22 μs | 1.00x faster | 0.01x | - | - | - | - |
30-
| For_Unsafe | 1000000 | 411.1 μs | 1.58 μs | 1.48 μs | 1.00x faster | 0.01x | - | - | - | - |
31-
| ForAdamczewski | 1000000 | 404.1 μs | 1.83 μs | 1.53 μs | 1.02x faster | 0.01x | - | - | - | - |
32-
| ForAdamczewskiUnsafe | 1000000 | 411.2 μs | 1.93 μs | 1.71 μs | 1.00x faster | 0.01x | - | - | - | - |
33-
| Span | 1000000 | 411.1 μs | 1.74 μs | 1.36 μs | 1.00x faster | 0.01x | - | - | - | - |
34-
| ArraySegment_Foreach | 1000000 | 2,790.2 μs | 10.03 μs | 7.83 μs | 6.78x slower | 0.06x | - | - | - | 1 B |
35-
| ArraySegment_For | 1000000 | 801.6 μs | 2.79 μs | 2.33 μs | 1.95x slower | 0.02x | - | - | - | - |
36-
| ArraySegment_AsSpan | 1000000 | 410.4 μs | 1.33 μs | 1.24 μs | 1.00x faster | 0.01x | - | - | - | - |
37-
| ArraySegment_AsArray | 1000000 | 560.8 μs | 2.97 μs | 2.63 μs | 1.36x slower | 0.01x | - | - | - | - |
38-
| Vector | 1000000 | 104.3 μs | 0.54 μs | 0.50 μs | 3.95x faster | 0.04x | - | - | - | - |
26+
| Method | Count | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated |
27+
|--------------------- |-------- |-----------:|---------:|---------:|-------------:|--------:|------:|------:|------:|----------:|
28+
| Foreach | 1000000 | 432.4 μs | 3.92 μs | 3.06 μs | baseline | | - | - | - | - |
29+
| For | 1000000 | 435.1 μs | 8.19 μs | 7.26 μs | 1.01x slower | 0.02x | - | - | - | - |
30+
| For_Unsafe | 1000000 | 434.8 μs | 8.67 μs | 8.11 μs | 1.00x slower | 0.02x | - | - | - | - |
31+
| ForAdamczewski | 1000000 | 369.4 μs | 6.03 μs | 5.03 μs | 1.17x faster | 0.02x | - | - | - | - |
32+
| ForAdamczewskiUnsafe | 1000000 | 436.1 μs | 4.05 μs | 3.38 μs | 1.01x slower | 0.01x | - | - | - | - |
33+
| Span | 1000000 | 431.5 μs | 2.91 μs | 2.43 μs | 1.00x faster | 0.01x | - | - | - | - |
34+
| ArraySegment_Foreach | 1000000 | 2,890.1 μs | 34.93 μs | 30.97 μs | 6.69x slower | 0.07x | - | - | - | 1 B |
35+
| ArraySegment_For | 1000000 | 836.4 μs | 9.11 μs | 7.60 μs | 1.94x slower | 0.02x | - | - | - | - |
36+
| ArraySegment_AsSpan | 1000000 | 430.0 μs | 4.37 μs | 3.65 μs | 1.01x faster | 0.01x | - | - | - | - |
37+
| ArraySegment_AsArray | 1000000 | 575.1 μs | 3.28 μs | 2.91 μs | 1.33x slower | 0.01x | - | - | - | - |
38+
| Vector | 1000000 | 118.6 μs | 1.91 μs | 2.12 μs | 3.63x faster | 0.08x | - | - | - | - |

NetFabric.Hyperlinq.Benchmarks/Benchmarks/ArrayIterationBenchmarks.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ public int ForAdamczewski()
7272
var sum2 = 0;
7373
for (var index = 0; index <= source.Length - 2; index += 2)
7474
{
75-
long i1 = index + 0;
76-
long i2 = index + 1;
77-
var c = source[i1];
78-
var d = source[i2];
75+
var c = source[index + 0];
76+
var d = source[index + 1];
7977

8078
sum1 += c;
8179
sum2 += d;
@@ -97,10 +95,8 @@ public unsafe int ForAdamczewskiUnsafe()
9795
var sum2 = 0;
9896
for (var index = 0; index <= len; index += 2)
9997
{
100-
long i1 = index + 0;
101-
long i2 = index + 1;
102-
var c = source[i1];
103-
var d = source[i2];
98+
var c = source[index + 0];
99+
var d = source[index + 1];
104100

105101
sum1 += c;
106102
sum2 += d;

NetFabric.Hyperlinq/Aggregation/Sum/Sum.ReadOnlySpan.cs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,11 @@ static TSource Sum<TSource>(this ReadOnlySpan<TSource> source)
2424
for (var index = 0; index < Vector<TSource>.Count; index++)
2525
sum = GenericsOperator.Add(vectorSum[index], sum);
2626

27-
for (var index = source.Length - (source.Length % Vector<TSource>.Count); index < source.Length; index++)
28-
{
29-
var item = source[index];
30-
sum = GenericsOperator.Add(item, sum);
31-
}
27+
var count = source.Length % Vector<TSource>.Count;
28+
source = source.Slice(source.Length - count, count);
3229
}
33-
else
34-
{
35-
foreach (var item in source)
36-
sum = GenericsOperator.Add(item, sum);
37-
}
38-
30+
foreach (var item in source)
31+
sum = GenericsOperator.Add(item, sum);
3932
return sum;
4033
}
4134

@@ -59,28 +52,20 @@ static TResult Sum<TSource, TResult, TVectorSelector, TSelector>(this ReadOnlySp
5952
for (var index = 0; index < Vector<TResult>.Count; index++)
6053
sum = GenericsOperator.Add(vectorSum[index], sum);
6154

62-
for (var index = source.Length - (source.Length % Vector<TSource>.Count); index < source.Length; index++)
63-
{
64-
var item = source[index];
65-
sum = GenericsOperator.Add(selector.Invoke(item), sum);
66-
}
67-
}
68-
else
69-
{
70-
foreach (var item in source)
71-
sum = GenericsOperator.Add(selector.Invoke(item), sum);
55+
var count = source.Length % Vector<TSource>.Count;
56+
source = source.Slice(source.Length - count, count);
7257
}
58+
foreach (var item in source)
59+
sum = GenericsOperator.Add(selector.Invoke(item), sum);
7360
return sum;
7461
}
7562

7663
static TSum Sum<TSource, TSum>(this ReadOnlySpan<TSource> source)
7764
where TSum : struct
7865
{
7966
var sum = default(TSum);
80-
8167
foreach (var item in source)
8268
sum = GenericsOperator.AddNullable(item, sum);
83-
8469
return sum;
8570
}
8671

NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void CopyTo(Span<TSource> span)
5151
using var enumerator = GetEnumerator();
5252
checked
5353
{
54-
for (var index = 0; enumerator.MoveNext() && index < span.Length; index++)
54+
for (var index = 0; enumerator.MoveNext(); index++)
5555
span[index] = enumerator.Current;
5656
}
5757
}
@@ -65,7 +65,7 @@ public void CopyTo(TSource[] array, int arrayIndex)
6565
collection.CopyTo(array, arrayIndex);
6666
break;
6767
default:
68-
CopyTo(array.AsSpan().Slice(arrayIndex));
68+
CopyTo(array.AsSpan(arrayIndex));
6969
break;
7070
}
7171
}

NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ReadOnlyList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void CopyTo(TSource[] array, int arrayIndex)
8686
collection.CopyTo(array, arrayIndex);
8787
break;
8888
default:
89-
CopyTo(array.AsSpan().Slice(arrayIndex));
89+
CopyTo(array.AsSpan(arrayIndex));
9090
break;
9191
}
9292
}

NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'1.ValueReadOnlyCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void CopyTo(Span<TSource> span)
6363

6464
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6565
public void CopyTo(TSource[] array, int arrayIndex)
66-
=> CopyTo(array.AsSpan().Slice(arrayIndex));
66+
=> CopyTo(array.AsSpan(arrayIndex));
6767

6868

6969
[MethodImpl(MethodImplOptions.AggressiveInlining)]

NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ReadOnlyCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void CopyTo(Span<TSource> span)
9898

9999
[MethodImpl(MethodImplOptions.AggressiveInlining)]
100100
public void CopyTo(TSource[] array, int arrayIndex)
101-
=> CopyTo(array.AsSpan().Slice(arrayIndex));
101+
=> CopyTo(array.AsSpan(arrayIndex));
102102

103103

104104
[MethodImpl(MethodImplOptions.AggressiveInlining)]

NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void CopyTo(TSource[] array, int arrayIndex)
105105
collection.CopyTo(array, arrayIndex);
106106
break;
107107
default:
108-
CopyTo(array.AsSpan().Slice(arrayIndex));
108+
CopyTo(array.AsSpan(arrayIndex));
109109
break;
110110
}
111111
}

NetFabric.Hyperlinq/Conversion/AsValueEnumerable/AsValueEnumerable'6.ValueReadOnlyList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void CopyTo(TSource[] array, int arrayIndex)
117117
collection.CopyTo(array, arrayIndex);
118118
break;
119119
default:
120-
CopyTo(array.AsSpan().Slice(arrayIndex));
120+
CopyTo(array.AsSpan(arrayIndex));
121121
break;
122122
}
123123
}

NetFabric.Hyperlinq/Generation/ValueEnumerable/Range.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void CopyTo(Span<int> span)
8888

8989
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9090
public void CopyTo(int[] array, int arrayIndex)
91-
=> CopyTo(array.AsSpan().Slice(arrayIndex));
91+
=> CopyTo(array.AsSpan(arrayIndex));
9292

9393

9494
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)