Benchmark organization improvements to reuse code.
This commit is contained in:
1 parent
c45af6a884
commit
46b074a35c
4 files changed
+55
-20
No files matched your search
@@ -1,4 +1,6 @@
|
|||||||
using Recyclable.Collections.Benchmarks.POC;
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using Recyclable.Collections.Benchmarks.Core;
|
||||||
|
using Recyclable.Collections.Benchmarks.POC;
|
||||||
|
|
||||||
namespace Recyclable.Collections.Benchmarks
|
namespace Recyclable.Collections.Benchmarks
|
||||||
{
|
{
|
||||||
@@ -25,9 +27,26 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void DoNothing<T>(T obj)
|
[GlobalSetup]
|
||||||
|
public virtual void Setup()
|
||||||
{
|
{
|
||||||
_ = obj;
|
Console.WriteLine("******* GLOBAL SETUP *******");
|
||||||
|
_testObjects = DataGenerator.EnumerateTestObjects(TestObjectCount);
|
||||||
|
Console.WriteLine("******* TEST DATA CREATED *******");
|
||||||
|
}
|
||||||
|
|
||||||
|
[GlobalCleanup]
|
||||||
|
public virtual void Cleanup()
|
||||||
|
{
|
||||||
|
Console.WriteLine("******* GLOBAL CLEANUP *******");
|
||||||
|
// Enable this if item type is changed to reference type
|
||||||
|
//if (_testObjects != null)
|
||||||
|
//{
|
||||||
|
// Array.Fill(_testObjects, 0);
|
||||||
|
//}
|
||||||
|
|
||||||
|
_testObjects = default;
|
||||||
|
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
|
|
||||||
public PooledList<long> TestObjectsAsPooledList => _testPooledList ?? throw new NullReferenceException("Something is wrong and the field is not initialized");
|
public PooledList<long> TestObjectsAsPooledList => _testPooledList ?? throw new NullReferenceException("Something is wrong and the field is not initialized");
|
||||||
|
|
||||||
[GlobalSetup]
|
public override void Setup()
|
||||||
public void Setup()
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("******* GLOBAL SETUP RAISED *******");
|
base.Setup();
|
||||||
_testObjects = EnumerateTestObjects().ToArray();
|
|
||||||
_testRecyclableArrayList = new(TestObjects, initialCapacity: TestObjectCount);
|
_testRecyclableArrayList = new(TestObjects, initialCapacity: TestObjectCount);
|
||||||
_testRecyclableList = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount);
|
_testRecyclableList = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount);
|
||||||
_testArray = TestObjects.ToArray();
|
_testArray = TestObjects.ToArray();
|
||||||
@@ -27,18 +25,8 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
_testPooledList = new PooledList<long>(TestObjects, ClearMode.Always);
|
_testPooledList = new PooledList<long>(TestObjects, ClearMode.Always);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<long> EnumerateTestObjects()
|
public override void Cleanup()
|
||||||
{
|
{
|
||||||
for (long i = 0; i < TestObjectCount; i++)
|
|
||||||
{
|
|
||||||
yield return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[GlobalCleanup]
|
|
||||||
public void Cleanup()
|
|
||||||
{
|
|
||||||
Console.WriteLine("******* GLOBAL CLEANUP *******");
|
|
||||||
_testRecyclableArrayList?.Dispose();
|
_testRecyclableArrayList?.Dispose();
|
||||||
_testRecyclableList?.Dispose();
|
_testRecyclableList?.Dispose();
|
||||||
_testPooledList?.Dispose();
|
_testPooledList?.Dispose();
|
||||||
@@ -46,7 +34,7 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
_testObjectsAsRecyclableArrayList = default;
|
_testObjectsAsRecyclableArrayList = default;
|
||||||
_testObjectsAsRecyclableList = default;
|
_testObjectsAsRecyclableList = default;
|
||||||
_testObjectsAsList = default;
|
_testObjectsAsList = default;
|
||||||
_testObjects = default;
|
base.Cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace Recyclable.Collections.Benchmarks.Core
|
||||||
|
{
|
||||||
|
public class DataGenerator
|
||||||
|
{
|
||||||
|
public static long[] EnumerateTestObjects(long testObjectCount)
|
||||||
|
{
|
||||||
|
var result = new long[testObjectCount];
|
||||||
|
Console.WriteLine("******* TEST DATA ARRAY CREATED *******");
|
||||||
|
|
||||||
|
Span<long> resultSpan = result;
|
||||||
|
for (int i = 0; i < testObjectCount; i++)
|
||||||
|
{
|
||||||
|
resultSpan[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Recyclable.Collections.Benchmarks.POC
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace Recyclable.Collections.Benchmarks.POC
|
||||||
{
|
{
|
||||||
public class PocBenchmarkBase
|
public class PocBenchmarkBase
|
||||||
{
|
{
|
||||||
@@ -21,5 +23,11 @@
|
|||||||
> 0 and <= 10 => (int)TestObjectCount,
|
> 0 and <= 10 => (int)TestObjectCount,
|
||||||
_ => TestObjectCount / Divider > 0 ? checked((int)(TestObjectCount / Divider)) : checked((int)TestObjectCount)
|
_ => TestObjectCount / Divider > 0 ? checked((int)(TestObjectCount / Divider)) : checked((int)TestObjectCount)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
protected static void DoNothing<T>(in T item)
|
||||||
|
{
|
||||||
|
_ = item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user