Smaller improvements and additional benchmarks setup
This commit is contained in:
1 parent
bc4f0576de
commit
f3198a45a4
4 files changed
+18
-19
No files matched your search
@@ -4,8 +4,8 @@ namespace Recyclable.Collections.Benchmarks
|
||||
{
|
||||
public class BenchmarkBase
|
||||
{
|
||||
[Params(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 128, 256, 512, 1024, 2048, 4096, 8192, 1_000_000)]
|
||||
public int TestObjectCount;
|
||||
[Params(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 128, 256, 512, 1024, 2048, 4096, 8192, 1_000_000)]
|
||||
public int TestObjectCount = 1; // = 1_000_000;
|
||||
public int BlockSize => TestObjectCount switch
|
||||
{
|
||||
0 => 1,
|
||||
@@ -14,13 +14,13 @@ namespace Recyclable.Collections.Benchmarks
|
||||
};
|
||||
|
||||
protected object[]? _testObjects;
|
||||
protected object[] TestObjects => _testObjects ??= Enumerable.Range(1, TestObjectCount).Select(x => new object()).ToArray();
|
||||
protected object[] TestObjects => _testObjects ?? throw new NullReferenceException("Something is wrong and the field is not initialized");
|
||||
|
||||
protected List<object>? _testObjectsAsList;
|
||||
protected List<object> TestObjectsAsList => _testObjectsAsList ??= TestObjects.ToList();
|
||||
protected List<object> TestObjectsAsList => _testObjectsAsList ?? throw new NullReferenceException("Something went wront and the field is not initialized");
|
||||
|
||||
protected RecyclableArrayList<object>? _testObjectsAsRecyclableArrayList;
|
||||
protected RecyclableArrayList<object> TestObjectsAsRecyclableArrayList => _testObjectsAsRecyclableArrayList ??= TestObjects.ToRecyclableArrayList();
|
||||
protected RecyclableArrayList<object> TestObjectsAsRecyclableArrayList => _testObjectsAsRecyclableArrayList ?? throw new NullReferenceException("Something is wrong and the field is not initialized");
|
||||
protected IEnumerable<object> TestObjectsAsIEnumerable => Enumerable.Range(1, TestObjectCount).Select(static x => new object());
|
||||
|
||||
protected static void DoNothing<T>(T obj)
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
{
|
||||
private object[] _testArray;
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
//[Benchmark(Baseline = true)]
|
||||
public void Array_Create_WithCapacity()
|
||||
{
|
||||
var data = new object[TestObjectCount];
|
||||
|
||||
@@ -4,21 +4,21 @@ namespace Recyclable.Collections.Benchmarks
|
||||
{
|
||||
public partial class RecyclableCollectionsBenchmarks : BenchmarkBase
|
||||
{
|
||||
[Benchmark(Baseline = true)]
|
||||
//[Benchmark(Baseline = true)]
|
||||
public void List_Create()
|
||||
{
|
||||
var list = new List<object>();
|
||||
DoNothing(list);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
//[Benchmark]
|
||||
public void List_Create_WithCapacity()
|
||||
{
|
||||
var list = new List<object>(TestObjectCount);
|
||||
DoNothing(list);
|
||||
}
|
||||
|
||||
//[Benchmark]
|
||||
[Benchmark]
|
||||
public void List_Add()
|
||||
{
|
||||
var data = TestObjects;
|
||||
@@ -30,7 +30,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
}
|
||||
}
|
||||
|
||||
//[Benchmark(Baseline = false)]
|
||||
[Benchmark(Baseline = true)]
|
||||
public void List_Add_WithCapacity()
|
||||
{
|
||||
var data = TestObjects;
|
||||
|
||||
+8
-9
@@ -9,25 +9,24 @@ namespace Recyclable.Collections.Benchmarks
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
Console.WriteLine("******* GLOBAL SETUP RAISED *******");
|
||||
_testObjects = Enumerable.Range(1, TestObjectCount).Select(x => new object()).ToArray();
|
||||
_testRecyclableArrayList = new(TestObjects, TestObjectCount);
|
||||
_testRecyclableList = new(TestObjects, TestObjectCount);
|
||||
_testArray = TestObjects.ToArray();
|
||||
_ = TestObjectsAsList;
|
||||
_ = TestObjectsAsRecyclableArrayList;
|
||||
_ = TestObjectsAsIEnumerable;
|
||||
_testObjectsAsList = TestObjects.ToList();
|
||||
_testObjectsAsRecyclableArrayList = TestObjects.ToRecyclableArrayList();
|
||||
}
|
||||
|
||||
|
||||
[GlobalCleanup]
|
||||
public void Cleanup()
|
||||
{
|
||||
Console.WriteLine("******* GLOBAL CLEANUP *******");
|
||||
_testRecyclableArrayList?.Dispose();
|
||||
_testRecyclableArrayList = default;
|
||||
_testRecyclableList?.Dispose();
|
||||
_testRecyclableList = default;
|
||||
TestObjectsAsRecyclableArrayList?.Dispose();
|
||||
_testObjectsAsRecyclableArrayList = default;
|
||||
_testArray = default;
|
||||
_testObjectsAsList = default;
|
||||
_testObjects = default;
|
||||
}
|
||||
@@ -39,14 +38,14 @@ namespace Recyclable.Collections.Benchmarks
|
||||
DoNothing(list);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
//[Benchmark]
|
||||
public void RecyclableArrayList_Create_WithCapacity()
|
||||
{
|
||||
using var list = new RecyclableArrayList<object>(TestObjectCount);
|
||||
DoNothing(list);
|
||||
}
|
||||
|
||||
//[Benchmark]
|
||||
[Benchmark]
|
||||
public void RecyclableArrayList_Add()
|
||||
{
|
||||
var data = TestObjects;
|
||||
@@ -58,7 +57,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
}
|
||||
}
|
||||
|
||||
//[Benchmark]
|
||||
[Benchmark]
|
||||
public void RecyclableArrayList_Add_WithCapacity()
|
||||
{
|
||||
var data = TestObjects;
|
||||
|
||||
Reference in new issue
Block a user