List<T> compatibility methods implemented. Unit tests extended. README.md updated.

This commit is contained in:
mlemanczyk committed 2023-10-07 13:35:48 +02:00
1 parent e6e7b4995a
commit 262590ed6e
26 files changed
+2721 -312

No files matched your search

@@ -60,7 +60,7 @@ namespace Recyclable.Collections.Benchmarks.POC
// [Params(RecyclableDefaults.MinItemsCountForParallelization * 3)]
// [Params(1_048_576)]
public virtual int TestObjectCount { get; set; } = 0; //8_192;//131_072; //1; //33_554_432; //524_288; //131_072;
public virtual int TestObjectCountForSlowMethods => (TestObjectCount / 2) + 1;// Math.Min(TestObjectCount, 131_072);
public virtual int TestObjectCountForSlowMethods { get; private set; }
// [Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200)]
// [Params(10, 20, 50, 100)]
@@ -103,6 +103,8 @@ namespace Recyclable.Collections.Benchmarks.POC
{
Console.WriteLine($"******* SETTING UP TEST CASE FOR BENCHMARK {{{DataType}}} *******");
TestObjectCountForSlowMethods = (TestObjectCount / 2) + 1;
BlockSize = TestObjectCount switch
{
0 => 1,
@@ -5,24 +5,10 @@ using Recyclable.Collections.Benchmarks.Core;
namespace Recyclable.Collections.Benchmarks.POC
{
public enum RecyclableLongListPocBenchmarkType
{
EnsureCapacity_ByPowOf2,
EnsureCapacityV1_ByPowOf2,
EnsureCapacityV3_ByPowOf2,
}
[MemoryDiagnoser]
public partial class RecyclableLongListPocBenchmarks : PocBenchmarkBase<RecyclableLongListPocBenchmarkType>
public partial class RecyclableLongListPocBenchmarks<T> : PocBenchmarkBase<T>
{
[Params(RecyclableLongListPocBenchmarkType.EnsureCapacity_ByPowOf2)]
public override RecyclableLongListPocBenchmarkType DataType { get => base.DataType; set => base.DataType = value; }
// [Params(BenchmarkType.Array, BenchmarkType.List, BenchmarkType.RecyclableList, BenchmarkType.RecyclableLongList)]
[Params(RecyclableLongListPocBenchmarkType.EnsureCapacityV1_ByPowOf2)]
public override RecyclableLongListPocBenchmarkType BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; }
private long[]? _testArray;
private long[]? _testArray;
public long[] TestObjects => _testArray ?? throw new NullReferenceException("Something is wrong and test objects are null");
public RecyclableLongList<long> TestObjectsAsRecyclableLongList => _testRecyclableLongList ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableLongList<long>)} is null");
@@ -31,34 +17,12 @@ namespace Recyclable.Collections.Benchmarks.POC
internal PooledList<long> TestPooledList => _testPooledList ?? throw new NullReferenceException($"Something is wrong and {nameof(PooledList<long>)} is null");
private static readonly MethodInfo _ensureCapacityNewFunc;
private static readonly MethodInfo _ensureCapacityV1Func;
private static readonly MethodInfo _ensureCapacityV3Func;
static RecyclableLongListPocBenchmarks()
{
_ensureCapacityNewFunc = typeof(RecyclableLongList<long>).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.NonPublic)
?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableLongList<long>)}");
_ensureCapacityV1Func = typeof(RecyclableLongListV1<long>).GetMethod("EnsureCapacity", BindingFlags.Instance | BindingFlags.NonPublic)
?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableLongListV1<long>)}");
_ensureCapacityV3Func = typeof(RecyclableLongListV3<long>).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.NonPublic)
?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableLongListV3<long>)}");
}
public static void Run()
{
var benchmark = new RecyclableLongListPocBenchmarks();
benchmark.Setup();
// benchmark.RecyclableLongList_EnsureCapacity_ByPowOf2();
// benchmark.RecyclableLongList_EnsureCapacityV1_ByPowOf2();
// benchmark.RecyclableLongList_EnsureCapacityV2_ByPowOf2();
// benchmark.RecyclableLongList_EnsureCapacityV3_ByPowOf2();
// benchmark.RecyclableLongList_EnsureCapacity_ByBlockSize();
// benchmark.RecyclableLongList_EnsureCapacityV1_ByBlockSize();
// benchmark.RecyclableLongList_EnsureCapacityV2_ByBlockSize();
// benchmark.RecyclableLongList_EnsureCapacityV3_ByBlockSize();
benchmark.Cleanup();
}
public override void Setup()
@@ -67,7 +31,7 @@ namespace Recyclable.Collections.Benchmarks.POC
_testArray = DataGenerator.EnumerateTestObjects(TestObjectCount);
base.Setup();
}
}
public override void Cleanup()
{
@@ -79,18 +43,5 @@ namespace Recyclable.Collections.Benchmarks.POC
base.Cleanup();
}
protected override Action? GetTestMethod(RecyclableLongListPocBenchmarkType benchmarkType) => benchmarkType switch
{
RecyclableLongListPocBenchmarkType.EnsureCapacity_ByPowOf2 => () => RecyclableLongList_EnsureCapacity_ByPowOf2(),
RecyclableLongListPocBenchmarkType.EnsureCapacityV1_ByPowOf2 => () => RecyclableLongList_EnsureCapacityV1_ByPowOf2(),
RecyclableLongListPocBenchmarkType.EnsureCapacityV3_ByPowOf2 => () => RecyclableLongList_EnsureCapacityV3_ByPowOf2(),
_ => throw CreateUnknownBenchmarkTypeException(benchmarkType),
};
protected override void PrepareData<T>(T benchmarkType)
{
base.PrepareData(benchmarkType);
}
}
}
}