This commit is contained in:
mlemanczyk committed 2023-06-11 22:41:01 +02:00
commit 985d5d173f
9 files changed
+36 -35

No files matched your search

@@ -17,8 +17,8 @@ namespace Recyclable.Collections.Benchmarks
public RecyclableCollectionsBenchmarks() : base() public RecyclableCollectionsBenchmarks() : base()
{ {
TestObjectCount = 1; TestObjectCount = 1;
BaselineBenchmarkType = RecyclableCollectionsBenchmarkSource.List; BaseDataType = RecyclableCollectionsBenchmarkSource.List;
BenchmarkType = RecyclableCollectionsBenchmarkSource.RecyclableLongList; DataType = RecyclableCollectionsBenchmarkSource.RecyclableLongList;
} }
[Params [Params
@@ -54,7 +54,7 @@ namespace Recyclable.Collections.Benchmarks
( (
RecyclableCollectionsBenchmarkSource.List RecyclableCollectionsBenchmarkSource.List
)] )]
public override RecyclableCollectionsBenchmarkSource BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } public override RecyclableCollectionsBenchmarkSource BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; }
[Params [Params
( (
@@ -64,7 +64,7 @@ namespace Recyclable.Collections.Benchmarks
RecyclableCollectionsBenchmarkSource.RecyclableList, RecyclableCollectionsBenchmarkSource.RecyclableList,
RecyclableCollectionsBenchmarkSource.RecyclableLongList RecyclableCollectionsBenchmarkSource.RecyclableLongList
)] )]
public override RecyclableCollectionsBenchmarkSource BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } public override RecyclableCollectionsBenchmarkSource DataType { get => base.DataType; set => base.DataType = value; }
protected override Action? GetTestMethod(RecyclableCollectionsBenchmarkSource benchmarkType) protected override Action? GetTestMethod(RecyclableCollectionsBenchmarkSource benchmarkType)
=> (Action?) GetType().GetMethod($"{benchmarkType}_{TestCase}", BindingFlags.Instance | BindingFlags.Public)?.CreateDelegate(typeof(Action), this) => (Action?) GetType().GetMethod($"{benchmarkType}_{TestCase}", BindingFlags.Instance | BindingFlags.Public)?.CreateDelegate(typeof(Action), this)
@@ -12,7 +12,7 @@ namespace Recyclable.Collections.Benchmarks.POC
public class BoolOrComparePocBenchmarks : PocBenchmarkBase<BoolOrComparePocBenchmarkType> public class BoolOrComparePocBenchmarks : PocBenchmarkBase<BoolOrComparePocBenchmarkType>
{ {
[Params(BoolOrComparePocBenchmarkType.Bool, BoolOrComparePocBenchmarkType.Compare)] [Params(BoolOrComparePocBenchmarkType.Bool, BoolOrComparePocBenchmarkType.Compare)]
public override BoolOrComparePocBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } public override BoolOrComparePocBenchmarkType DataType { get => base.DataType; set => base.DataType = value; }
[Params(8)] [Params(8)]
public override int TestObjectCount { get => base.TestObjectCount; set => base.TestObjectCount = value; } public override int TestObjectCount { get => base.TestObjectCount; set => base.TestObjectCount = value; }
@@ -38,10 +38,10 @@ namespace Recyclable.Collections.Benchmarks.POC
DelegateVsComparerPocBenchmarkType.ListOfUnboxedStructs, DelegateVsComparerPocBenchmarkType.ListOfUnboxedStructs,
DelegateVsComparerPocBenchmarkType.StaticFunc DelegateVsComparerPocBenchmarkType.StaticFunc
)] )]
public override DelegateVsComparerPocBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } public override DelegateVsComparerPocBenchmarkType DataType { get => base.DataType; set => base.DataType = value; }
[Params(DelegateVsComparerPocBenchmarkType.Comparer)] [Params(DelegateVsComparerPocBenchmarkType.Comparer)]
public override DelegateVsComparerPocBenchmarkType BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } public override DelegateVsComparerPocBenchmarkType BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; }
#region Dummy classes #region Dummy classes
@@ -6,13 +6,13 @@ namespace Recyclable.Collections.Benchmarks.POC
{ {
public abstract class PocBenchmarkBase<TBenchmarkType> public abstract class PocBenchmarkBase<TBenchmarkType>
{ {
public virtual TBenchmarkType? BenchmarkType { get; set; } public virtual TBenchmarkType? DataType { get; set; }
public virtual TBenchmarkType? BaselineBenchmarkType { get; set; } public virtual TBenchmarkType? BaseDataType { get; set; }
private Action? _testMethod; private Action? _testMethod;
protected Action TestMethod protected Action TestMethod
{ {
get => _testMethod ?? throw new OperationCanceledException("Skip - Custom benchmark run in progress"); get => _testMethod ?? throw new OperationCanceledException("Skip - No actual defined");
set => _testMethod = value; set => _testMethod = value;
} }
@@ -41,20 +41,21 @@ namespace Recyclable.Collections.Benchmarks.POC
// [Params(192, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144)] // [Params(192, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144)]
// [Params(524_288, 786_432, 1_048_576)] // [Params(524_288, 786_432, 1_048_576)]
// [Params(262_144, 393_216, 524_288)] // [Params(262_144, 393_216, 524_288)]
//[Params(850_000)] // [Params(850_000)]
// [Params(RecyclableDefaults.MaxPooledBlockSize)] // [Params(RecyclableDefaults.MaxPooledBlockSize)]
// [Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 32, 40, 50, 60, 80, 90, 100, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 10_000_000, 33_554_432, 50_000_000, 100_000_000)] // [Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 32, 40, 50, 60, 80, 90, 100, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 10_000_000, 33_554_432, 50_000_000, 100_000_000)]
[Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 32, 40, 50, 60, 80, 90, 100, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072)] [Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 32, 40, 50, 60, 80, 90, 100, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072)]
//[Params(RecyclableDefaults.MinItemsCountForParallelization, 1_048_576, 2_097_152, 4_194_304, 8_388_608, 16_777_216, 33_554_432, RecyclableDefaults.MaxPooledBlockSize)] //[Params(RecyclableDefaults.MinItemsCountForParallelization, 1_048_576, 2_097_152, 4_194_304, 8_388_608, 16_777_216, 33_554_432, RecyclableDefaults.MaxPooledBlockSize)]
// [Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 32, 40, 50, 60, 80, 90, 100, 128)] // [Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 32, 40, 50, 60, 80, 90, 100, 128)]
// [Params(1, 10, 1024, 10240, RecyclableDefaults.MinPooledArrayLength, RecyclableDefaults.MinItemsCountForParallelization)]
// [Params(RecyclableDefaults.MinItemsCountForParallelization * 3)] // [Params(RecyclableDefaults.MinItemsCountForParallelization * 3)]
// [Params(1_048_576)] // [Params(1_048_576)]
public virtual int TestObjectCount { get; set; } = 1; //33_554_432; //524_288; //131_072; public virtual int TestObjectCount { get; set; } = 1; //33_554_432; //524_288; //131_072;
public virtual int TestObjectCountForSlowMethods => (TestObjectCount / 2) + 1;// Math.Min(TestObjectCount, 131_072); public virtual int TestObjectCountForSlowMethods => (TestObjectCount / 2) + 1;// Math.Min(TestObjectCount, 131_072);
//[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(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)] // [Params(10, 20, 50, 100)]
//[Params(1, 10)] // [Params(1, 10)]
public int Divider = 10; public int Divider = 10;
//public int BlockSize = 1_048_576;//int.MaxValue - 1; //public int BlockSize = 1_048_576;//int.MaxValue - 1;
public int BlockSize => TestObjectCount switch public int BlockSize => TestObjectCount switch
@@ -96,23 +97,23 @@ namespace Recyclable.Collections.Benchmarks.POC
[GlobalSetup] [GlobalSetup]
public virtual void Setup() public virtual void Setup()
{ {
Console.WriteLine($"******* SETTING UP TEST CASE FOR BENCHMARK {{{BenchmarkType}}} *******"); Console.WriteLine($"******* SETTING UP TEST CASE FOR BENCHMARK {{{DataType}}} *******");
if (!EqualityComparer<TBenchmarkType>.Default.Equals(BaselineBenchmarkType, default)) if (!EqualityComparer<TBenchmarkType>.Default.Equals(BaseDataType, default))
{ {
Console.WriteLine("******* SETTING UP BASELINE DATA *******"); Console.WriteLine("******* SETTING UP BASELINE DATA *******");
PrepareData(BaselineBenchmarkType); PrepareData(BaseDataType);
_baselineMethod = GetTestMethod(BaselineBenchmarkType); _baselineMethod = GetTestMethod(BaseDataType);
} }
//~ We don't want to prepare data if baseline data is the same is benchmark data. //~ We don't want to prepare data if baseline data is the same is benchmark data.
//~ One would override another - waste of time & resources. //~ One would override another - waste of time & resources.
if (!EqualityComparer<TBenchmarkType>.Default.Equals(BaselineBenchmarkType, BenchmarkType)) if (!EqualityComparer<TBenchmarkType>.Default.Equals(BaseDataType, DataType))
{ {
Console.WriteLine("******* SETTING UP TEST CASE DATA *******"); Console.WriteLine("******* SETTING UP TEST CASE DATA *******");
//~ If BaselineBenchmarkType == null, then we'll come here only if BaselineBenchmarkType != null. //~ If BaseDataType == null, then we'll come here only if DataType != null.
PrepareData(BenchmarkType!); PrepareData(DataType!);
_testMethod = GetTestMethod(BenchmarkType); _testMethod = GetTestMethod(DataType);
} }
Console.WriteLine("******* DATA PREPARED *******"); Console.WriteLine("******* DATA PREPARED *******");
@@ -23,11 +23,11 @@ namespace Recyclable.Collections.Benchmarks.POC
public partial class RecyclableLongListPocBenchmarks : PocBenchmarkBase<RecyclableLongListPocBenchmarkType> public partial class RecyclableLongListPocBenchmarks : PocBenchmarkBase<RecyclableLongListPocBenchmarkType>
{ {
[Params(RecyclableLongListPocBenchmarkType.IndexOf)] [Params(RecyclableLongListPocBenchmarkType.IndexOf)]
public override RecyclableLongListPocBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } public override RecyclableLongListPocBenchmarkType DataType { get => base.DataType; set => base.DataType = value; }
// [Params(BenchmarkType.Array, BenchmarkType.List, BenchmarkType.RecyclableList, BenchmarkType.RecyclableLongList)] // [Params(BenchmarkType.Array, BenchmarkType.List, BenchmarkType.RecyclableList, BenchmarkType.RecyclableLongList)]
[Params(RecyclableLongListPocBenchmarkType.IndexOf_PooledList)] [Params(RecyclableLongListPocBenchmarkType.IndexOf_PooledList)]
public override RecyclableLongListPocBenchmarkType BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } 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 long[] TestObjects => _testArray ?? throw new NullReferenceException("Something is wrong and test objects are null");
@@ -131,7 +131,7 @@ namespace Recyclable.Collections.Benchmarks.POC
{ {
base.PrepareData(benchmarkType); base.PrepareData(benchmarkType);
switch (BenchmarkType) switch (benchmarkType)
{ {
case RecyclableLongListPocBenchmarkType.IndexOfV1: case RecyclableLongListPocBenchmarkType.IndexOfV1:
_testRecyclableLongListIndexOfV1 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); _testRecyclableLongListIndexOfV1 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount);
@@ -12,10 +12,10 @@ namespace Recyclable.Collections.Benchmarks.POC
public class RoundBenchmarks : PocBenchmarkBase<RoundBenchmarkType> public class RoundBenchmarks : PocBenchmarkBase<RoundBenchmarkType>
{ {
[Params(RoundBenchmarkType.MathFloor)] [Params(RoundBenchmarkType.MathFloor)]
public override RoundBenchmarkType BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } public override RoundBenchmarkType BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; }
[Params(RoundBenchmarkType.MathRound, RoundBenchmarkType.WithTypecasting)] [Params(RoundBenchmarkType.MathRound, RoundBenchmarkType.WithTypecasting)]
public override RoundBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } public override RoundBenchmarkType DataType { get => base.DataType; set => base.DataType = value; }
private const double OptimalParallelSearchStep = 0.329; private const double OptimalParallelSearchStep = 0.329;
@@ -21,11 +21,11 @@ namespace Recyclable.Collections.Benchmarks.POC
SpanVsArrayBenchmarkType.ArrayGetWithVar, SpanVsArrayBenchmarkType.SpanGet, SpanVsArrayBenchmarkType.ArrayGetWithVar, SpanVsArrayBenchmarkType.SpanGet,
SpanVsArrayBenchmarkType.ArraySetWithField, SpanVsArrayBenchmarkType.ArraySetWithVar, SpanVsArrayBenchmarkType.SpanSet SpanVsArrayBenchmarkType.ArraySetWithField, SpanVsArrayBenchmarkType.ArraySetWithVar, SpanVsArrayBenchmarkType.SpanSet
)] )]
public override SpanVsArrayBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } public override SpanVsArrayBenchmarkType DataType { get => base.DataType; set => base.DataType = value; }
[Params(SpanVsArrayBenchmarkType.ArrayGetWithField)] [Params(SpanVsArrayBenchmarkType.ArrayGetWithField)]
// [Params(SpanVsArrayBenchmarkType.ArraySetWithField)] // [Params(SpanVsArrayBenchmarkType.ArraySetWithField)]
public override SpanVsArrayBenchmarkType BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } public override SpanVsArrayBenchmarkType BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; }
protected override Action GetTestMethod(SpanVsArrayBenchmarkType benchmarkType) => benchmarkType switch protected override Action GetTestMethod(SpanVsArrayBenchmarkType benchmarkType) => benchmarkType switch
{ {
@@ -83,10 +83,10 @@ namespace Recyclable.Collections.Benchmarks.POC
public object? ItemToFind { get; set; } public object? ItemToFind { get; set; }
[Params(WhenParallelSearchBenchmarkType.IndexOfParallel)] [Params(WhenParallelSearchBenchmarkType.IndexOfParallel)]
public override WhenParallelSearchBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } public override WhenParallelSearchBenchmarkType DataType { get => base.DataType; set => base.DataType = value; }
[Params(WhenParallelSearchBenchmarkType.IndexOfSequentially)] [Params(WhenParallelSearchBenchmarkType.IndexOfSequentially)]
public override WhenParallelSearchBenchmarkType BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } public override WhenParallelSearchBenchmarkType BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; }
private long DoLongIndexOfSequentially() private long DoLongIndexOfSequentially()
{ {
@@ -304,7 +304,7 @@ namespace Recyclable.Collections.Benchmarks.POC
ItemToFind ??= _testData.Last(); ItemToFind ??= _testData.Last();
} }
protected override Action? GetTestMethod(WhenParallelSearchBenchmarkType benchmarkType) => BenchmarkType switch protected override Action? GetTestMethod(WhenParallelSearchBenchmarkType benchmarkType) => benchmarkType switch
{ {
WhenParallelSearchBenchmarkType.IndexOfSequentially => IndexOfSequentially, WhenParallelSearchBenchmarkType.IndexOfSequentially => IndexOfSequentially,
WhenParallelSearchBenchmarkType.IndexOfParallel => IndexOfParallel, WhenParallelSearchBenchmarkType.IndexOfParallel => IndexOfParallel,
+3 -3
View File
@@ -28,9 +28,9 @@ public static class Program
//foreach (var _ in Enumerable.Range(1, 1000)) //foreach (var _ in Enumerable.Range(1, 1000))
//{ //{
// benchmark.RecyclableLongList_Remove_FirstItems(); // benchmark.RecyclableLongList_Remove_FirstItems();
// benchmark.RecyclableLongList_RemoveAt_LastItems(); // benchmark.RecyclableLongList_RemoveAt_LastItems();
// benchmark.List_RemoveAt_LastItems(); // benchmark.List_RemoveAt_LastItems();
//} //}
//benchmark.Cleanup(); //benchmark.Cleanup();