diff --git a/Recyclable.Collections.Benchmarks/BenchmarkBase.cs b/Recyclable.Collections.Benchmarks/BenchmarkBase.cs index f5dcafe..ac7e1cf 100644 --- a/Recyclable.Collections.Benchmarks/BenchmarkBase.cs +++ b/Recyclable.Collections.Benchmarks/BenchmarkBase.cs @@ -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? _testObjectsAsList; - protected List TestObjectsAsList => _testObjectsAsList ??= TestObjects.ToList(); + protected List TestObjectsAsList => _testObjectsAsList ?? throw new NullReferenceException("Something went wront and the field is not initialized"); protected RecyclableArrayList? _testObjectsAsRecyclableArrayList; - protected RecyclableArrayList TestObjectsAsRecyclableArrayList => _testObjectsAsRecyclableArrayList ??= TestObjects.ToRecyclableArrayList(); + protected RecyclableArrayList TestObjectsAsRecyclableArrayList => _testObjectsAsRecyclableArrayList ?? throw new NullReferenceException("Something is wrong and the field is not initialized"); protected IEnumerable TestObjectsAsIEnumerable => Enumerable.Range(1, TestObjectCount).Select(static x => new object()); protected static void DoNothing(T obj) diff --git a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.Array.cs b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.Array.cs index cab42a8..3ebe96d 100644 --- a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.Array.cs +++ b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.Array.cs @@ -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]; diff --git a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.List.cs b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.List.cs index 9b3388f..4f62236 100644 --- a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.List.cs +++ b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.List.cs @@ -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(); DoNothing(list); } - [Benchmark] + //[Benchmark] public void List_Create_WithCapacity() { var list = new List(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; diff --git a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableArrayList.cs b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableArrayList.cs index c5a70b4..2640941 100644 --- a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableArrayList.cs +++ b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableArrayList.cs @@ -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(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;