using BenchmarkDotNet.Attributes; namespace Recyclable.Collections.Benchmarks { public class BenchmarkBase { //[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, 1_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, 1_000_000)] public long TestObjectCount = 1_000_000; //[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(1, 10)] public int Divider = 10; public int BlockSize => TestObjectCount switch { 0 => 1, > 0 and <= 10 => (int)TestObjectCount, _ => TestObjectCount / Divider > 0 ? checked((int)(TestObjectCount / Divider)) : checked((int)TestObjectCount) }; 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(); // } //} }