Cleanup. Hints and warnings either disabled or fixed. Typos fixed.

This commit is contained in:
mlemanczyk committed 2023-07-01 17:07:16 +02:00
1 parent 2317f53d51
commit c20b252a6c
17 files changed
+108 -68

No files matched your search

@@ -53,7 +53,7 @@ namespace Recyclable.Collections.Benchmarks.POC
private struct MyComparerStruct<T> : IComparer<T>
{
public int Compare(T? x, T? y) => Comparer<T>.Default.Compare(x, y);
public readonly int Compare(T? x, T? y) => Comparer<T>.Default.Compare(x, y);
}
private class MyComparer : IComparer<long>
@@ -132,7 +132,7 @@ namespace Recyclable.Collections.Benchmarks.POC
}
}
private void TestWithDelegate<T>(Compare<long> compareFunc)
private void TestWithDelegate(Compare<long> compareFunc)
{
var testData = _testObjects!.ToArray();
for (var itemIdx = 0; itemIdx < testData.Length - 1; itemIdx++)
@@ -177,7 +177,7 @@ namespace Recyclable.Collections.Benchmarks.POC
public void Delegate()
{
TestWithDelegate<long>((x, y) => (x - y) switch
TestWithDelegate((x, y) => (x - y) switch
{
> 0 => 1,
< 0 => -1,
@@ -1,12 +1,14 @@
using BenchmarkDotNet.Attributes;
using System.Runtime.CompilerServices;
#pragma warning disable CA1822
namespace Recyclable.Collections.Benchmarks.POC
{
public class LessOperatorVsAndOperatorBenchmarks
{
private const int bitShift = 1 << 31;
private static Random _rnd = new(1);
private static readonly Random _rnd = new(1);
private static int num = -Math.Abs(_rnd.Next());
public void Setup()
@@ -17,10 +19,13 @@ namespace Recyclable.Collections.Benchmarks.POC
public void Cleanup() { }
#pragma warning disable RCS1163, IDE0060
[MethodImpl(MethodImplOptions.NoInlining)]
private static void DoNothing<T>(T item)
{ }
{
}
#pragma warning restore RCS1163
[Benchmark(Baseline = true)]
public void CompareWithLess()
@@ -4,6 +4,8 @@ using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
#pragma warning disable xUnit1026, RCS1163, IDE0060
namespace Recyclable.Collections.Benchmarks.POC
{
[MemoryDiagnoser]
@@ -124,7 +126,7 @@ namespace Recyclable.Collections.Benchmarks.POC
DoNothing(result, remainder);
}
private void CalculateWithSubractWithWhileWithSse2(long i)
private void CalculateWithSubtractWithWhileWithSse2(long i)
{
var state = Vector128.Create(i, 0);
int blockSize = BlockSize;
@@ -137,7 +139,7 @@ namespace Recyclable.Collections.Benchmarks.POC
DoNothing(state.GetElement(1), state.GetElement(0));
}
private void CalculateWithMixedApproachWithSubractWithWhile(long i)
private void CalculateWithMixedApproachWithSubtractWithWhile(long i)
{
long remainder;
if (i >= _cutoff)
@@ -317,7 +319,7 @@ namespace Recyclable.Collections.Benchmarks.POC
long testNumber = TestNumber;
for (long i = testNumber; i >= _lastCaseIndex; i--)
{
CalculateWithSubractWithWhileWithSse2(i);
CalculateWithSubtractWithWhileWithSse2(i);
}
}
@@ -327,7 +329,7 @@ namespace Recyclable.Collections.Benchmarks.POC
long testNumber = TestNumber;
for (long i = testNumber; i >= _lastCaseIndex; i--)
{
CalculateWithMixedApproachWithSubractWithWhile(i);
CalculateWithMixedApproachWithSubtractWithWhile(i);
}
}
@@ -4,6 +4,8 @@ using System.Collections;
using System.Numerics;
using System.Runtime.CompilerServices;
#pragma warning disable CA1825, RCS1085, CA2208
namespace Recyclable.Collections.Benchmarks.POC
{
#region RecyclableLongList v1
@@ -26,7 +28,10 @@ namespace Recyclable.Collections.Benchmarks.POC
protected ArrayPool<T[]> _memoryBlocksPool;
protected ArrayPool<T> _blockArrayPool;
#nullable disable
protected T[][] _memoryBlocks;
#nullable restore
private long _capacity;
public long Capacity
@@ -341,10 +346,10 @@ namespace Recyclable.Collections.Benchmarks.POC
? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity))
: requestedCapacity;
newCapacity = Resize(ref _memoryBlocks!, _blockSize, _capacity, newCapacity, _memoryBlocksPool, _blockArrayPool);
newCapacity = Resize(ref _memoryBlocks, _blockSize, _capacity, newCapacity, _memoryBlocksPool, _blockArrayPool);
if (newCapacity > 0 && _capacity == 0)
{
_blockSize = _memoryBlocks[0].Length;
_blockSize = _memoryBlocks![0].Length;
_blockSizePow2Shift = MathUtils.GetPow2Shift(_blockSize);
}
@@ -361,8 +366,8 @@ namespace Recyclable.Collections.Benchmarks.POC
if (expectedItemsCount > 0)
{
_capacity = Resize(ref _memoryBlocks!, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
if (_memoryBlocks.Length > 0)
_capacity = Resize(ref _memoryBlocks, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
if (_memoryBlocks!.Length > 0)
{
minBlockSize = _memoryBlocks[0].Length;
}
@@ -387,8 +392,8 @@ namespace Recyclable.Collections.Benchmarks.POC
if (expectedItemsCount > 0)
{
_capacity = Resize(ref _memoryBlocks!, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
if (_memoryBlocks.Length > 0)
_capacity = Resize(ref _memoryBlocks, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
if (_memoryBlocks!.Length > 0)
{
minBlockSize = _memoryBlocks[0].Length;
}
@@ -6,6 +6,8 @@ using System.Collections;
using System.Numerics;
using System.Runtime.CompilerServices;
#pragma warning disable CA1825, RCS1085, CA2208
namespace Recyclable.Collections.Benchmarks.POC
{
#region ItemRangesIterator V1
@@ -19,7 +21,6 @@ namespace Recyclable.Collections.Benchmarks.POC
public ItemRangeV1()
{
}
public ItemRangeV1(int blockIndex, int startingItemIndex, long itemsToSearchCount)
@@ -560,7 +561,7 @@ namespace Recyclable.Collections.Benchmarks.POC
{
break;
}
};
}
}
else
{
@@ -3802,7 +3803,7 @@ namespace Recyclable.Collections.Benchmarks.POC
[MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.AggressiveInlining)]
private long DoIndexOfParallel(T item)
{
{
var synchronizationContext = new ParallelSynchronizationContextV4(1);
// (long)(_longCount * 0.329) => most efficient step, based on benchmarks
Iterate(synchronizationContext, this, item, ScheduleIndexOfTasks);
@@ -1,5 +1,7 @@
using BenchmarkDotNet.Attributes;
#pragma warning disable RCS1085
namespace Recyclable.Collections.Benchmarks.POC
{
public class RefVsInstanceMemberPocBenchmarks