using Recyclable.Collections.Benchmarks.POC; namespace Recyclable.Collections.Benchmarks { public class BenchmarkBase : PocBenchmarkBase { protected object[]? _testObjects; protected object[] TestObjects => _testObjects ?? throw new NullReferenceException("Something is wrong and the field is not initialized"); protected List? _testObjectsAsList; protected List TestObjectsAsList => _testObjectsAsList ?? throw new NullReferenceException("Something went wront and the field is not initialized"); protected RecyclableArrayList? _testObjectsAsRecyclableArrayList; protected RecyclableArrayList TestObjectsAsRecyclableArrayList => _testObjectsAsRecyclableArrayList ?? throw new NullReferenceException("Something is wrong and the field is not initialized"); protected RecyclableList? _testObjectsAsRecyclableList; protected RecyclableList TestObjectsAsRecyclableList => _testObjectsAsRecyclableList ?? throw new NullReferenceException("Something is wrong and the field is not initialized"); protected IEnumerable TestObjectsAsIEnumerable { get { for (long i = 0; i < TestObjectCount; i++) { yield return new object(); } } } protected static void DoNothing(T obj) { _ = obj; } } //[MemoryDiagnoser] //public class ListVsLinkedListBenchmarks //{ // [Benchmark] // public void RecyclableArrayList() // { // var data = TestObjects; // var dataCount = TestObjectCount; // using var list = new RecyclableArrayList(initialCapacity: dataCount); // for (long i = 0; i < dataCount; i++) // { // list.Add(data[i]); // } // for (long i = 0; i < list.LongCount; i++) // { // DoNothing(list[i]); // } // list.Clear(); // } // [Benchmark(Baseline = true)] // public void RecyclableList() // { // var data = TestObjects; // long dataCount = TestObjectCount; // using var list = new RecyclableList(BlockSize, totalItemsCount: dataCount); // for (long i = 0; i < dataCount; i++) // { // list.Add(data[i]); // } // for (long i = 0; i < list.LongCount; i++) // { // DoNothing(list[i]); // } // list.Clear(); // } // //[Benchmark] // public void List() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new List(capacity: dataCount); // for (var i = 0; i < dataCount; i++) // { // list.Add(data[i]); // } // for (var i = 0; i < list.Count; i++) // { // DoNothing(list[i]); // } // list.Clear(); // } // //[Benchmark] // public void LinkedList() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new LinkedList(); // for (var i = 0; i < dataCount; i++) // { // _ = list.AddLast(data[i]); // } // foreach (var node in list) // { // DoNothing(node); // } // list.Clear(); // } // //[Benchmark] // public void RecyclableQueue() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new RecyclableQueue(BlockSize); // for (var i = 0; i < dataCount; i++) // { // list.Enqueue(data[i]); // } // while (list.LongCount > 0) // { // DoNothing(list.Dequeue()); // } // list.Clear(); // } // //[Benchmark] // public void Queue() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new Queue(capacity: dataCount); // for (var i = 0; i < dataCount; i++) // { // list.Enqueue(data[i]); // } // while (list.Count > 0) // { // DoNothing(list.Dequeue()); // } // list.Clear(); // } // //[Benchmark] // public void PriorityQueue() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new PriorityQueue(initialCapacity: dataCount); // for (var i = 0; i < dataCount; i++) // { // list.Enqueue(data[i], i); // } // while (list.Count > 0) // { // DoNothing(list.Dequeue()); // } // list.Clear(); // } // //[Benchmark] // public void RecyclableSortedList_InUpdateMode() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new RecyclableSortedList(BlockSize); // list.BeginUpdate(); // for (var i = 0; i < dataCount; i++) // { // list.Add(i, data[i]); // } // list.EndUpdate(); // for (var i = 0; i < list.LongCount; i++) // { // DoNothing(list[i]); // } // list.Clear(); // } // //[Benchmark] // public void RecyclableSortedList() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new RecyclableSortedList(BlockSize); // for (var i = 0; i < dataCount; i++) // { // list.Add(i, data[i]); // } // for (var i = 0; i < list.LongCount; i++) // { // DoNothing(list[i]); // } // list.Clear(); // } // //[Benchmark] // public void SortedList() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new SortedList(); // for (var i = 0; i < dataCount; i++) // { // list.Add(i, data[i]); // } // for (var i = 0; i < list.Count; i++) // { // DoNothing(list[i]); // } // list.Clear(); // } // //[Benchmark] // public void RecyclableStack() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new RecyclableStack(BlockSize); // for (var i = 0; i < dataCount; i++) // { // list.Push(data[i]); // } // while (list.LongCount > 0) // { // DoNothing(list.Pop()); // } // list.Clear(); // } // //[Benchmark] // public void Stack() // { // var data = TestObjects; // var dataCount = TestObjectCount; // var list = new Stack(); // for (var i = 0; i < dataCount; i++) // { // list.Push(data[i]); // } // while (list.Count > 0) // { // DoNothing(list.Pop()); // } // list.Clear(); // } //} }