Several hints removed & code cleaned up.
This commit is contained in:
1 parent
b038bcfdc9
commit
dfb671aff7
26 files changed
+106
-138
No files matched your search
@@ -63,6 +63,5 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list.Contains(data[^(i + 1)]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,6 @@ namespace Recyclable.Collections.Benchmarks
|
||||
|
||||
if (nextItemBlockIndex == data.LastBlockWithData)
|
||||
{
|
||||
|
||||
var memoryBlock = new Span<long>(memoryBlocks[nextItemBlockIndex], 0, data.NextItemIndex);
|
||||
for (var itemIndex = 0; itemIndex < memoryBlock.Length; itemIndex++)
|
||||
{
|
||||
@@ -119,8 +118,6 @@ namespace Recyclable.Collections.Benchmarks
|
||||
public void RecyclableList_GetItem_AsForEach()
|
||||
{
|
||||
var data = TestObjectsAsRecyclableList;
|
||||
var dataCount = TestObjectCount;
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
DoNothing(item);
|
||||
|
||||
@@ -75,6 +75,5 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list.LongIndexOf(data[i]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,5 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list.LongIndexOf(data[i]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,5 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list.LongIndexOf(data[^(i + 1)]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,5 @@ namespace Recyclable.Collections.Benchmarks
|
||||
var data = TestObjectsAsRecyclableList;
|
||||
DoNothing(data.LongCount);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,5 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list.Remove(data[i]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Collections.Pooled;
|
||||
|
||||
|
||||
namespace Recyclable.Collections.Benchmarks
|
||||
{
|
||||
public partial class RecyclableCollectionsBenchmarks
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Recyclable.Collections.Benchmarks.Core
|
||||
{
|
||||
public class DataGenerator
|
||||
public static class DataGenerator
|
||||
{
|
||||
public static long[] EnumerateTestObjects(long testObjectCount)
|
||||
{
|
||||
@@ -15,6 +15,5 @@ namespace Recyclable.Collections.Benchmarks.Core
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,14 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
benchmark.Bool();
|
||||
benchmark.Compare();
|
||||
}
|
||||
|
||||
|
||||
private static void DoNothing<T>(T result, [CallerMemberName] string? callerName = null)
|
||||
{
|
||||
//Console.WriteLine($"{callerName}: result = {result}");
|
||||
}
|
||||
|
||||
private bool _testBool = true;
|
||||
private int _blockSize = 8;
|
||||
private readonly bool _testBool = true;
|
||||
private readonly int _blockSize = 8;
|
||||
|
||||
[Benchmark(Baseline = false)]
|
||||
public void Bool()
|
||||
|
||||
@@ -64,13 +64,13 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
|
||||
private const int _objectCount = 1_000_000;
|
||||
private static readonly IEnumerable<long> _testObjects = Enumerable.Range(1, _objectCount).Select(x => (long)x);
|
||||
private static readonly IEnumerable<Func<long, long, int>> _testListOfFunctions = _testObjects.Select<long, Func<long, long, int>>(static x => new MyComparer().Compare);
|
||||
private static readonly IEnumerable<IComparer<long>> _testListOfComparers = _testObjects.Select(x => (IComparer<long>)new MyComparer());
|
||||
private static readonly IEnumerable<Compare<long>> _testListOfDelegates = _testObjects.Select(x => new Compare<long>((x, y) => new MyComparer().Compare(x, y)));
|
||||
private static readonly IEnumerable<Func<long, long, int>> _testListOfFunctions = _testObjects.Select<long, Func<long, long, int>>(static _ => new MyComparer().Compare);
|
||||
private static readonly IEnumerable<IComparer<long>> _testListOfComparers = _testObjects.Select(_ => (IComparer<long>)new MyComparer());
|
||||
private static readonly IEnumerable<Compare<long>> _testListOfDelegates = _testObjects.Select(_ => new Compare<long>((x, y) => new MyComparer().Compare(x, y)));
|
||||
private static readonly IEnumerable<Func<long, long, int>> _testListOfLocalFunctions = GetLocalFunctions(_testObjects);
|
||||
private static readonly IEnumerable<MyComparer> _testListOfClasses = _testObjects.Select(x => new MyComparer());
|
||||
private static readonly IEnumerable<MyComparerStruct<long>> _testListOfStructs = _testObjects.Select(x => new MyComparerStruct<long>());
|
||||
private static readonly IEnumerable<IComparer<long>> _testListOfBoxedStructs = _testObjects.Select(x => (IComparer<long>)new MyComparerStruct<long>());
|
||||
private static readonly IEnumerable<MyComparer> _testListOfClasses = _testObjects.Select(_ => new MyComparer());
|
||||
private static readonly IEnumerable<MyComparerStruct<long>> _testListOfStructs = _testObjects.Select(_ => new MyComparerStruct<long>());
|
||||
private static readonly IEnumerable<IComparer<long>> _testListOfBoxedStructs = _testObjects.Select(_ => (IComparer<long>)new MyComparerStruct<long>());
|
||||
private static IEnumerable<TComparer> _testListOfUnboxedStructs<TComparer, TValue>() where TComparer : IComparer<TValue>, new()
|
||||
{
|
||||
foreach (var item in _testObjects)
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
benchmark.XDivYMulX();
|
||||
benchmark.XDivYMulXWithLocalVar();
|
||||
}
|
||||
|
||||
|
||||
private long _cutoff;
|
||||
private Vector128<long> _increment;
|
||||
private long _lastCaseIndex;
|
||||
|
||||
+9
-11
@@ -586,7 +586,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
_nextItemIndex = (int)(targetCapacity & (blockSize - 1));
|
||||
_nextItemBlockIndex = targetBlockIndex;
|
||||
|
||||
}
|
||||
|
||||
_longCount = targetCapacity;
|
||||
@@ -872,7 +871,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region RecyclableList v2
|
||||
@@ -1117,10 +1115,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
||||
/// <param name="minBlockSizeBitShift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
||||
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableListV2{T}.Resize(RecyclableListV2{T}, int, byte, long)"/>.</param>
|
||||
/// <remarks>For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||
/// <remarks><para>
|
||||
/// For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||
/// index calculations, i.e. makes them logical operations on bits.
|
||||
///
|
||||
/// This method checks for integral overflow.
|
||||
/// </para>
|
||||
/// <para>This method checks for integral overflow.</para>
|
||||
/// </remarks>
|
||||
/// <returns>The maximum no. of items <paramref name="list"/> can store.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
@@ -1485,7 +1484,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
_nextItemIndex = checked((int)(targetCapacity & (blockSize - 1)));
|
||||
_nextItemBlockIndex = targetBlockIndex;
|
||||
|
||||
}
|
||||
|
||||
_longCount = targetCapacity;
|
||||
@@ -2089,10 +2087,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
||||
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
||||
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
||||
/// <remarks>For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||
/// <remarks><para>
|
||||
/// For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||
/// index calculations, i.e. makes them logical operations on bits.
|
||||
///
|
||||
/// This method checks for integral overflow.
|
||||
/// </para>
|
||||
/// <para>This method checks for integral overflow.</para>
|
||||
/// </remarks>
|
||||
/// <returns>The maximum no. of items <paramref name="list"/> can store.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
@@ -2446,7 +2445,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
||||
_nextItemBlockIndex = targetBlockIndex;
|
||||
|
||||
}
|
||||
|
||||
_longCount = targetCapacity;
|
||||
@@ -2804,7 +2802,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
public partial class RecyclableListPocBenchmarks
|
||||
|
||||
@@ -404,10 +404,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
||||
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
||||
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
||||
/// <remarks>For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||
/// <remarks><para>
|
||||
/// For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||
/// index calculations, i.e. makes them logical operations on bits.
|
||||
///
|
||||
/// This method checks for integral overflow.
|
||||
/// </para>
|
||||
/// <para>This method checks for integral overflow.</para>
|
||||
/// </remarks>
|
||||
/// <remarks>
|
||||
/// This method doesn't support downsizing the memory block. As such it doesn't release excessive blocks. This is to for additional performance
|
||||
@@ -457,7 +458,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
}
|
||||
|
||||
blockIndex = sourceBlockCount;
|
||||
do
|
||||
while (true)
|
||||
{
|
||||
newMemoryBlocks[blockIndex] = blockArrayPool.Rent(minBlockSize);
|
||||
if (blockIndex + 1 < requiredBlockCount)
|
||||
@@ -468,24 +469,24 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
blockIndex = sourceBlockCount;
|
||||
do
|
||||
{
|
||||
newMemoryBlocks[blockIndex] = new T[minBlockSize];
|
||||
if (blockIndex + 1 < requiredBlockCount)
|
||||
{
|
||||
blockIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
newMemoryBlocks[blockIndex] = new T[minBlockSize];
|
||||
if (blockIndex + 1 < requiredBlockCount)
|
||||
{
|
||||
blockIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list._reservedBlockCount = requiredBlockCount;
|
||||
@@ -773,7 +774,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
||||
_nextItemBlockIndex = targetBlockIndex;
|
||||
|
||||
}
|
||||
|
||||
_longCount = targetCapacity;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
benchmark.RefToInt2();
|
||||
benchmark.RefToInt3();
|
||||
}
|
||||
|
||||
|
||||
private readonly TestCase _testCase = new();
|
||||
private static void DoNothing(int count)
|
||||
{
|
||||
|
||||
@@ -22,12 +22,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
//[Params(329_000, 512_000, 750_000, 1_000_000, 3_290_000)]
|
||||
//public int Step { get; set; } = 329_000; // This was the fastest so far
|
||||
|
||||
private static readonly int _numberOfProcessors = Environment.ProcessorCount;
|
||||
private RecyclableList<long>? _testData;
|
||||
|
||||
public object? ItemToFind { get; set; }
|
||||
|
||||
[GlobalSetup]
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
_testData = Enumerable.Range(1, TestObjectCount).Cast<long>().ToRecyclableList(BlockSize);
|
||||
@@ -40,7 +39,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
_testData = default;
|
||||
}
|
||||
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void IndexOfSequentially()
|
||||
{
|
||||
@@ -262,7 +260,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// if (threadIndex + 1 < numberOfRanges && blockIndex <= _testData.LastBlockWithData)
|
||||
// {
|
||||
// threadIndex++;
|
||||
|
||||
Reference in new issue
Block a user