From 9429218c6294966cc24a3b727fda89a59f137e24 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 21 May 2023 20:09:38 +0200 Subject: [PATCH] RecyclableList renamed to RecyclableLongList. --- .../Benchmarks/Add.cs | 4 +- .../Benchmarks/AddRangeWhenSourceIsArray.cs | 4 +- .../AddRangeWhenSourceIsIEnumerable.cs | 4 +- .../Benchmarks/AddRangeWhenSourceIsIList.cs | 10 +- .../Benchmarks/AddRangeWhenSourceIsList.cs | 4 +- .../AddRangeWhenSourceIsSameType.cs | 4 +- .../Benchmarks/AddRange_WithCapacity.cs | 4 +- .../Benchmarks/Add_WithCapacity.cs | 4 +- .../Benchmarks/Contains_FirstItems.cs | 4 +- .../Benchmarks/Contains_LastItems.cs | 4 +- .../Benchmarks/Count.cs | 4 +- .../Benchmarks/Create.cs | 4 +- .../Benchmarks/Create_WithCapacity.cs | 4 +- .../Benchmarks/GetItem..cs | 20 +-- .../Benchmarks/IndexOf_BestAndWorstCases.cs | 8 +- .../Benchmarks/IndexOf_FirstItems.cs | 8 +- .../Benchmarks/IndexOf_LastItems.cs | 8 +- .../Benchmarks/LongCount.cs | 4 +- .../RecyclableCollections.Benchmarks.cs | 4 +- .../Benchmarks/RemoveAt_FirstItems.cs | 4 +- .../Benchmarks/RemoveAt_LastItems.cs | 4 +- .../Benchmarks/Remove_FirstItems.cs | 4 +- .../Benchmarks/Remove_LastItems.cs | 4 +- .../Benchmarks/SetItem.cs | 4 +- .../POC/RecyclableListPoc.Benchmarks.cs | 157 ------------------ ...eLongListPoc.Benchmarks.EnsureCapacity.cs} | 106 ++++++------ ...cyclableLongListPoc.Benchmarks.IndexOf.cs} | 148 ++++++++--------- .../POC/RecyclableLongListPoc.Benchmarks.cs | 157 ++++++++++++++++++ ...cyclableLongListPos.Benchmarks.IndexOf.txt | 26 +++ .../POC/WhenParallelSearchBenchmarks.cs | 6 +- Recyclable.Collections.Benchmarks/Program.cs | 6 +- .../RecyclableBenchmarkBase.cs | 18 +- .../Results/AllInOneBenchmarks.txt | 56 +++---- Recyclable.Collections/RecyclableArrayList.cs | 6 +- ...s => RecyclableLongList.IndexOfHelpers.cs} | 40 +++-- ...ecyclableList.cs => RecyclableLongList.cs} | 28 ++-- ...ons.cs => RecyclableLongListExtensions.cs} | 12 +- .../RecyclableSortedList.cs | 2 +- Recyclable.Collections/RecyclableStack.cs | 4 +- Recyclable.Collections/SearchConfiguration.cs | 2 +- .../RecyclableArrayListTests.cs | 60 +++---- ...tData.cs => RecyclableLongListTestData.cs} | 8 +- ...istTests.cs => RecyclableLongListTests.cs} | 128 +++++++------- .../RecyclableQueueTests.cs | 4 +- .../RecyclableStackTests.cs | 4 +- 45 files changed, 576 insertions(+), 532 deletions(-) delete mode 100644 Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.cs rename Recyclable.Collections.Benchmarks/POC/{RecyclableListPoc.Benchmarks.EnsureCapacity.cs => RecyclableLongListPoc.Benchmarks.EnsureCapacity.cs} (94%) rename Recyclable.Collections.Benchmarks/POC/{RecyclableListPoc.Benchmarks.IndexOf.cs => RecyclableLongListPoc.Benchmarks.IndexOf.cs} (95%) create mode 100644 Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.cs create mode 100644 Recyclable.Collections.Benchmarks/POC/RecyclableLongListPos.Benchmarks.IndexOf.txt rename Recyclable.Collections/{RecyclableList.IndexOfHelpers.cs => RecyclableLongList.IndexOfHelpers.cs} (88%) rename Recyclable.Collections/{RecyclableList.cs => RecyclableLongList.cs} (95%) rename Recyclable.Collections/{RecyclableListExtensions.cs => RecyclableLongListExtensions.cs} (88%) rename Recyclable.CollectionsTests/{RecyclableListTestData.cs => RecyclableLongListTestData.cs} (91%) rename Recyclable.CollectionsTests/{RecyclableListTests.cs => RecyclableLongListTests.cs} (69%) diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Add.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Add.cs index 32173a2..12778f3 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Add.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Add.cs @@ -37,11 +37,11 @@ namespace Recyclable.Collections.Benchmarks } } - public void RecyclableList_Add() + public void RecyclableLongList_Add() { var data = TestObjects; var dataCount = TestObjectCount; - using var list = new RecyclableList(); + using var list = new RecyclableLongList(); for (var i = 0; i < dataCount; i++) { list.Add(data[i]); diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsArray.cs b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsArray.cs index 5bc8b09..a5bf6e3 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsArray.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsArray.cs @@ -25,10 +25,10 @@ namespace Recyclable.Collections.Benchmarks list.AddRange(data); } - public void RecyclableList_AddRangeWhenSourceIsArray() + public void RecyclableLongList_AddRangeWhenSourceIsArray() { var data = TestObjects; - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); list.AddRange(data); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIEnumerable.cs b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIEnumerable.cs index 51866dd..c212673 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIEnumerable.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIEnumerable.cs @@ -25,10 +25,10 @@ namespace Recyclable.Collections.Benchmarks list.AddRange(data); } - public void RecyclableList_AddRangeWhenSourceIsIEnumerable() + public void RecyclableLongList_AddRangeWhenSourceIsIEnumerable() { var data = TestObjectsAsIEnumerable; - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); list.AddRange(data); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIList.cs b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIList.cs index 15ea875..c734da0 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIList.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsIList.cs @@ -6,7 +6,7 @@ namespace Recyclable.Collections.Benchmarks { public void List_AddRangeWhenSourceIsIList() { - var data = (IList)TestObjectsAsRecyclableList; + var data = (IList)TestObjectsAsRecyclableLongList; var list = new List(); list.AddRange(data); } @@ -20,15 +20,15 @@ namespace Recyclable.Collections.Benchmarks public void RecyclableArrayList_AddRangeWhenSourceIsIList() { - var data = (IList)TestObjectsAsRecyclableList; + var data = (IList)TestObjectsAsRecyclableLongList; using var list = new RecyclableArrayList(); list.AddRange(data); } - public void RecyclableList_AddRangeWhenSourceIsIList() + public void RecyclableLongList_AddRangeWhenSourceIsIList() { - var data = (IList)TestObjectsAsRecyclableList; - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + var data = (IList)TestObjectsAsRecyclableLongList; + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); list.AddRange(data); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsList.cs b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsList.cs index f1c07d2..0ca986c 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsList.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsList.cs @@ -25,10 +25,10 @@ namespace Recyclable.Collections.Benchmarks list.AddRange(data); } - public void RecyclableList_AddRangeWhenSourceIsList() + public void RecyclableLongList_AddRangeWhenSourceIsList() { var data = TestObjectsAsList; - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); list.AddRange(data); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsSameType.cs b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsSameType.cs index 3eed14a..c33a4e5 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsSameType.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/AddRangeWhenSourceIsSameType.cs @@ -18,10 +18,10 @@ namespace Recyclable.Collections.Benchmarks list.AddRange(data); } - public void RecyclableList_AddRangeWhenSourceIsRecyclableArrayList() + public void RecyclableLongList_AddRangeWhenSourceIsRecyclableArrayList() { var data = TestObjectsAsRecyclableArrayList; - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); list.AddRange(data); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/AddRange_WithCapacity.cs b/Recyclable.Collections.Benchmarks/Benchmarks/AddRange_WithCapacity.cs index 1694833..37fa179 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/AddRange_WithCapacity.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/AddRange_WithCapacity.cs @@ -28,11 +28,11 @@ namespace Recyclable.Collections.Benchmarks list.AddRange(data); } - public void RecyclableList_AddRange_WithCapacity() + public void RecyclableLongList_AddRange_WithCapacity() { var data = TestObjects; var dataCount = TestObjectCount; - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: dataCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: dataCount); list.AddRange(data); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Add_WithCapacity.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Add_WithCapacity.cs index d727255..9734b20 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Add_WithCapacity.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Add_WithCapacity.cs @@ -37,11 +37,11 @@ namespace Recyclable.Collections.Benchmarks } } - public void RecyclableList_Add_WithCapacity() + public void RecyclableLongList_Add_WithCapacity() { var data = TestObjects; var dataCount = TestObjectCount; - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: dataCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: dataCount); for (var i = 0; i < dataCount; i++) { list.Add(data[i]); diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Contains_FirstItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Contains_FirstItems.cs index bdfa8dc..6bf4e1d 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Contains_FirstItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Contains_FirstItems.cs @@ -46,10 +46,10 @@ } } - public void RecyclableList_Contains_FirstItems() + public void RecyclableLongList_Contains_FirstItems() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Contains_LastItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Contains_LastItems.cs index 68b9e3a..8f41041 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Contains_LastItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Contains_LastItems.cs @@ -46,10 +46,10 @@ } } - public void RecyclableList_Contains_LastItems() + public void RecyclableLongList_Contains_LastItems() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Count.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Count.cs index 0a45e1b..45f18bb 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Count.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Count.cs @@ -26,9 +26,9 @@ DoNothing(data.Count); } - public void RecyclableList_Count() + public void RecyclableLongList_Count() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; DoNothing(data.Count); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Create.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Create.cs index 710da7d..2aacb8b 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Create.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Create.cs @@ -22,9 +22,9 @@ namespace Recyclable.Collections.Benchmarks DoNothing(list); } - public static void RecyclableList_Create() + public static void RecyclableLongList_Create() { - using var list = new RecyclableList(); + using var list = new RecyclableLongList(); DoNothing(list); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Create_WithCapacity.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Create_WithCapacity.cs index ba87e09..bceb830 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Create_WithCapacity.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Create_WithCapacity.cs @@ -28,9 +28,9 @@ namespace Recyclable.Collections.Benchmarks DoNothing(list); } - public void RecyclableList_Create_WithCapacity() + public void RecyclableLongList_Create_WithCapacity() { - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); DoNothing(list); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/GetItem..cs b/Recyclable.Collections.Benchmarks/Benchmarks/GetItem..cs index 26c5828..2388a24 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/GetItem..cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/GetItem..cs @@ -42,9 +42,9 @@ } } - public void RecyclableList_GetItem() + public void RecyclableLongList_GetItem() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCount; for (var i = 0; i < dataCount; i++) { @@ -52,9 +52,9 @@ } } - public void RecyclableList_GetItem_AsSpan() + public void RecyclableLongList_GetItem_AsSpan() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; int blockSize = data.BlockSize; int nextItemBlockIndex = data.NextItemBlockIndex; @@ -78,9 +78,9 @@ } } - public void RecyclableList_GetItem_AsArray() + public void RecyclableLongList_GetItem_AsArray() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; int blockSize = data.BlockSize; int nextItemBlockIndex = data.NextItemBlockIndex; @@ -105,18 +105,18 @@ } } - public void RecyclableList_GetItem_AsForEach() + public void RecyclableLongList_GetItem_AsForEach() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; foreach (var item in data) { DoNothing(item); } } - public void RecyclableList_GetItem_AsWhile() + public void RecyclableLongList_GetItem_AsWhile() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; long dataCount = TestObjectCount; if (dataCount == 0) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_BestAndWorstCases.cs b/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_BestAndWorstCases.cs index 650ba99..e1a4710 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_BestAndWorstCases.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_BestAndWorstCases.cs @@ -50,10 +50,10 @@ } } - public void RecyclableList_IndexOf_BestAndWorstCases() + public void RecyclableLongList_IndexOf_BestAndWorstCases() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCountForSlowMethods; for (var i = 0; i < dataCount; i++) { @@ -62,10 +62,10 @@ } } - public void RecyclableList_LongIndexOf_BestAndWorstCases() + public void RecyclableLongList_LongIndexOf_BestAndWorstCases() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCountForSlowMethods; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_FirstItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_FirstItems.cs index df4ca9e..992d33a 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_FirstItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_FirstItems.cs @@ -46,10 +46,10 @@ } } - public void RecyclableList_IndexOf_FirstItems() + public void RecyclableLongList_IndexOf_FirstItems() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCountForSlowMethods; for (var i = 0; i < dataCount; i++) { @@ -57,10 +57,10 @@ } } - public void RecyclableList_LongIndexOf_FirstItems() + public void RecyclableLongList_LongIndexOf_FirstItems() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCountForSlowMethods; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_LastItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_LastItems.cs index ab77a17..3d8b937 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_LastItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/IndexOf_LastItems.cs @@ -46,10 +46,10 @@ } } - public void RecyclableList_IndexOf_LastItems() + public void RecyclableLongList_IndexOf_LastItems() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCountForSlowMethods; for (var i = 0; i < dataCount; i++) { @@ -57,10 +57,10 @@ } } - public void RecyclableList_LongIndexOf_LastItems() + public void RecyclableLongList_LongIndexOf_LastItems() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCountForSlowMethods; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/LongCount.cs b/Recyclable.Collections.Benchmarks/Benchmarks/LongCount.cs index 2870f4d..9640ecd 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/LongCount.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/LongCount.cs @@ -8,9 +8,9 @@ DoNothing(data.LongLength); } - public void RecyclableList_LongCount() + public void RecyclableLongList_LongCount() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; DoNothing(data.LongCount); } } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/RecyclableCollections.Benchmarks.cs b/Recyclable.Collections.Benchmarks/Benchmarks/RecyclableCollections.Benchmarks.cs index 5aa2adb..5bb8227 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/RecyclableCollections.Benchmarks.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/RecyclableCollections.Benchmarks.cs @@ -18,7 +18,7 @@ namespace Recyclable.Collections.Benchmarks { TestObjectCount = 1; BaselineBenchmarkType = RecyclableCollectionsBenchmarkSource.PooledList; - BenchmarkType = RecyclableCollectionsBenchmarkSource.RecyclableList; + BenchmarkType = RecyclableCollectionsBenchmarkSource.RecyclableLongList; } [Params @@ -62,7 +62,7 @@ namespace Recyclable.Collections.Benchmarks RecyclableCollectionsBenchmarkSource.List, RecyclableCollectionsBenchmarkSource.PooledList, RecyclableCollectionsBenchmarkSource.RecyclableArrayList, - RecyclableCollectionsBenchmarkSource.RecyclableList + RecyclableCollectionsBenchmarkSource.RecyclableLongList )] public override RecyclableCollectionsBenchmarkSource BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_FirstItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_FirstItems.cs index 5bb65cb..8959972 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_FirstItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_FirstItems.cs @@ -37,10 +37,10 @@ namespace Recyclable.Collections.Benchmarks } } - public void RecyclableList_RemoveAt_FirstItems() + public void RecyclableLongList_RemoveAt_FirstItems() { var data = TestObjects; - using var list = new RecyclableList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_LastItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_LastItems.cs index f4b808e..77a3576 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_LastItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/RemoveAt_LastItems.cs @@ -37,10 +37,10 @@ namespace Recyclable.Collections.Benchmarks } } - public void RecyclableList_RemoveAt_LastItems() + public void RecyclableLongList_RemoveAt_LastItems() { var data = TestObjects; - using var list = new RecyclableList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount; for (var i = data.Length - 1; i > data.Length - dataCount - 1; i--) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Remove_FirstItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Remove_FirstItems.cs index 3d61a1c..ae15e61 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Remove_FirstItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Remove_FirstItems.cs @@ -37,10 +37,10 @@ namespace Recyclable.Collections.Benchmarks } } - public void RecyclableList_Remove_FirstItems() + public void RecyclableLongList_Remove_FirstItems() { var data = TestObjects; - using var list = new RecyclableList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/Remove_LastItems.cs b/Recyclable.Collections.Benchmarks/Benchmarks/Remove_LastItems.cs index 374a722..a727493 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/Remove_LastItems.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/Remove_LastItems.cs @@ -37,10 +37,10 @@ namespace Recyclable.Collections.Benchmarks } } - public void RecyclableList_Remove_LastItems() + public void RecyclableLongList_Remove_LastItems() { var data = TestObjects; - using var list = new RecyclableList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount; for (var i = data.Length - 1; i > data.Length - dataCount - 1; i--) { diff --git a/Recyclable.Collections.Benchmarks/Benchmarks/SetItem.cs b/Recyclable.Collections.Benchmarks/Benchmarks/SetItem.cs index 689a5e1..115a391 100644 --- a/Recyclable.Collections.Benchmarks/Benchmarks/SetItem.cs +++ b/Recyclable.Collections.Benchmarks/Benchmarks/SetItem.cs @@ -43,9 +43,9 @@ } } - public void RecyclableList_SetItem() + public void RecyclableLongList_SetItem() { - var data = TestObjectsAsRecyclableList; + var data = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCount; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.cs b/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.cs deleted file mode 100644 index 581622a..0000000 --- a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System.Reflection; -using BenchmarkDotNet.Attributes; -using Collections.Pooled; -using Recyclable.Collections.Benchmarks.Core; - -namespace Recyclable.Collections.Benchmarks.POC -{ - public enum RecyclableListPocBenchmarkType - { - IndexOfV1, - IndexOfV2, - IndexOfV3, - IndexOfV4, - IndexOf_PooledList, - IndexOf, - EnsureCapacity_ByPowOf2, - EnsureCapacityV1_ByPowOf2, - EnsureCapacityV2_ByPowOf2, - EnsureCapacityV3_ByPowOf2, - } - - [MemoryDiagnoser] - public partial class RecyclableListPocBenchmarks : PocBenchmarkBase - { - [Params(RecyclableListPocBenchmarkType.IndexOf)] - public override RecyclableListPocBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } - - // [Params(BenchmarkType.Array, BenchmarkType.List, BenchmarkType.RecyclableArrayList, BenchmarkType.RecyclableList)] - [Params(RecyclableListPocBenchmarkType.IndexOf_PooledList)] - public override RecyclableListPocBenchmarkType BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } - - private long[]? _testArray; - public long[] TestObjects => _testArray ?? throw new NullReferenceException("Something is wrong and test objects are null"); - - public RecyclableList TestObjectsAsRecyclableList => _testRecyclableList ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableList)} is null"); - private RecyclableListIndexOfV1? _testRecyclableListIndexOfV1; - internal RecyclableListIndexOfV1 TestObjectsAsRecyclableListIndexOfV1 => _testRecyclableListIndexOfV1 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableListIndexOfV1)} is null"); - private RecyclableListIndexOfV2? _testRecyclableListIndexOfV2; - private RecyclableList? _testRecyclableList; - internal RecyclableListIndexOfV2 TestObjectsAsRecyclableListIndexOfV2 => _testRecyclableListIndexOfV2 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableListIndexOfV2)} is null"); - private RecyclableListIndexOfV3? _testRecyclableListIndexOfV3; - internal RecyclableListIndexOfV3 TestObjectsAsRecyclableListIndexOfV3 => _testRecyclableListIndexOfV3 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableListIndexOfV3)} is null"); - private RecyclableListIndexOfV4? _testRecyclableListIndexOfV4; - internal RecyclableListIndexOfV4 TestObjectsAsRecyclableListIndexOfV4 => _testRecyclableListIndexOfV4 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableListIndexOfV4)} is null"); - private PooledList? _testPooledList; - internal PooledList TestPooledList => _testPooledList ?? throw new NullReferenceException($"Something is wrong and {nameof(PooledList)} is null"); - - private static readonly MethodInfo _ensureCapacityNewFunc; - private static readonly MethodInfo _ensureCapacityV1Func; - private static readonly MethodInfo _ensureCapacityV2Func; - private static readonly MethodInfo _ensureCapacityV3Func; - - static RecyclableListPocBenchmarks() - { - _ensureCapacityNewFunc = typeof(RecyclableList).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.NonPublic) - ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableList)}"); - - _ensureCapacityV1Func = typeof(RecyclableListV1).GetMethod("EnsureCapacity", BindingFlags.Instance | BindingFlags.NonPublic) - ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableListV1)}"); - - _ensureCapacityV2Func = typeof(RecyclableListV2).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.Public) - ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableListV2)}"); - - _ensureCapacityV3Func = typeof(RecyclableListV3).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.NonPublic) - ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableListV3)}"); - } - - public static void Run() - { - var benchmark = new RecyclableListPocBenchmarks(); - benchmark.Setup(); - // benchmark.RecyclableList_EnsureCapacity_ByPowOf2(); - // benchmark.RecyclableList_EnsureCapacityV1_ByPowOf2(); - // benchmark.RecyclableList_EnsureCapacityV2_ByPowOf2(); - // benchmark.RecyclableList_EnsureCapacityV3_ByPowOf2(); - // benchmark.RecyclableList_EnsureCapacity_ByBlockSize(); - // benchmark.RecyclableList_EnsureCapacityV1_ByBlockSize(); - // benchmark.RecyclableList_EnsureCapacityV2_ByBlockSize(); - // benchmark.RecyclableList_EnsureCapacityV3_ByBlockSize(); - benchmark.RecyclableList_IndexOf(); - benchmark.RecyclableList_IndexOfV1(); - benchmark.RecyclableList_IndexOfV2(); - benchmark.RecyclableList_IndexOfV3(); - benchmark.RecyclableList_IndexOfV4(); - benchmark.Cleanup(); - } - - public override void Setup() - { - Console.WriteLine("******* SETTING UP EXPECTED RESULTS DATA *******"); - _testArray = DataGenerator.EnumerateTestObjects(TestObjectCount); - - base.Setup(); - } - - public override void Cleanup() - { - _testArray = null; - _testRecyclableList?.Dispose(); - _testRecyclableList = null; - _testRecyclableListIndexOfV1?.Dispose(); - _testRecyclableListIndexOfV1 = null; - _testRecyclableListIndexOfV2?.Dispose(); - _testRecyclableListIndexOfV2 = null; - _testRecyclableListIndexOfV3?.Dispose(); - _testRecyclableListIndexOfV3 = null; - _testRecyclableListIndexOfV4?.Dispose(); - _testRecyclableListIndexOfV4 = null; - _testPooledList?.Dispose(); - _testPooledList = null; - - base.Cleanup(); - } - - protected override Action? GetTestMethod(RecyclableListPocBenchmarkType benchmarkType) => benchmarkType switch - { - RecyclableListPocBenchmarkType.IndexOfV1 => () => RecyclableList_IndexOfV1(), - RecyclableListPocBenchmarkType.IndexOfV2 => () => RecyclableList_IndexOfV2(), - RecyclableListPocBenchmarkType.IndexOfV3 => () => RecyclableList_IndexOfV3(), - RecyclableListPocBenchmarkType.IndexOfV4 => () => RecyclableList_IndexOfV4(), - RecyclableListPocBenchmarkType.IndexOf_PooledList => () => PooledList_IndexOf(), - RecyclableListPocBenchmarkType.IndexOf => () => RecyclableList_IndexOf(), - RecyclableListPocBenchmarkType.EnsureCapacity_ByPowOf2 => () => RecyclableList_EnsureCapacity_ByPowOf2(), - RecyclableListPocBenchmarkType.EnsureCapacityV1_ByPowOf2 => () => RecyclableList_EnsureCapacityV1_ByPowOf2(), - RecyclableListPocBenchmarkType.EnsureCapacityV2_ByPowOf2 => () => RecyclableList_EnsureCapacityV2_ByPowOf2(), - RecyclableListPocBenchmarkType.EnsureCapacityV3_ByPowOf2 => () => RecyclableList_EnsureCapacityV3_ByPowOf2(), - _ => throw CreateUnknownBenchmarkTypeException(benchmarkType), - }; - - protected override void PrepareData(T benchmarkType) - { - base.PrepareData(benchmarkType); - - switch (BenchmarkType) - { - case RecyclableListPocBenchmarkType.IndexOfV1: - _testRecyclableListIndexOfV1 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); - break; - case RecyclableListPocBenchmarkType.IndexOfV2: - _testRecyclableListIndexOfV2 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); - break; - case RecyclableListPocBenchmarkType.IndexOfV3: - _testRecyclableListIndexOfV3 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); - break; - case RecyclableListPocBenchmarkType.IndexOfV4: - _testRecyclableListIndexOfV4 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); - break; - case RecyclableListPocBenchmarkType.IndexOf_PooledList: - _testPooledList = new PooledList(TestObjects, ClearMode.Auto); - break; - case RecyclableListPocBenchmarkType.IndexOf: - _testRecyclableList = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); - break; - } - } - } -} diff --git a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.EnsureCapacity.cs similarity index 94% rename from Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs rename to Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.EnsureCapacity.cs index 8c320c8..046bc7d 100644 --- a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs +++ b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.EnsureCapacity.cs @@ -6,9 +6,9 @@ using System.Runtime.CompilerServices; namespace Recyclable.Collections.Benchmarks.POC { - #region RecyclableList v1 + #region RecyclableLongList v1 - internal class RecyclableListV1 : IDisposable, IList + internal class RecyclableLongListV1 : IDisposable, IList { private const int ItemNotFoundIndex = -1; @@ -352,7 +352,7 @@ namespace Recyclable.Collections.Benchmarks.POC return newCapacity; } - public RecyclableListV1(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListV1(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) { memoryBlocksPool ??= _defaultMemoryBlocksPool; blockArrayPool ??= _defaultBlockArrayPool; @@ -378,7 +378,7 @@ namespace Recyclable.Collections.Benchmarks.POC } } - public RecyclableListV1(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListV1(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) { memoryBlocksPool ??= _defaultMemoryBlocksPool; blockArrayPool ??= _defaultBlockArrayPool; @@ -520,7 +520,7 @@ namespace Recyclable.Collections.Benchmarks.POC _nextItemBlockIndex = targetBlockIndex; } - public void AddRange(RecyclableListV1 items) + public void AddRange(RecyclableLongListV1 items) { if (items.LongCount == 0) { @@ -691,9 +691,9 @@ namespace Recyclable.Collections.Benchmarks.POC public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.MinPooledArrayLength) { - if (source is RecyclableListV1 sourceRecyclableList) + if (source is RecyclableLongListV1 sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -849,7 +849,7 @@ namespace Recyclable.Collections.Benchmarks.POC IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableListV1() + ~RecyclableLongListV1() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); @@ -873,9 +873,9 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - #region RecyclableList v2 + #region RecyclableLongList v2 - internal class RecyclableListV2 : IDisposable, IList + internal class RecyclableLongListV2 : IDisposable, IList { private const int ItemNotFoundIndex = -1; @@ -920,7 +920,7 @@ namespace Recyclable.Collections.Benchmarks.POC public int NextItemIndex => _nextItemIndex; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - private static void CopyItems(RecyclableListV2 list, long index) + private static void CopyItems(RecyclableLongListV2 list, long index) { T[][] memoryBlocks = list._memoryBlocks; int nextItemIndex = list._nextItemIndex; @@ -1111,10 +1111,10 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// Creates a set of new memory buffers, if needed, to allow storing at minimum no. of items. /// - /// that needs to be resized. + /// that needs to be resized. /// Minimal requested block size. It MUST be rounded to the power of 2, see remarks. /// Pre-calculated bit shifting value for left & right shift operations against. - /// The minimum no. of items MUST be able to store after . + /// The minimum no. of items MUST be able to store after . /// /// For performance reasons, MUST a power of 2. This simplifies a lot block & item /// index calculations, i.e. makes them logical operations on bits. @@ -1123,7 +1123,7 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// The maximum no. of items can store. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static long Resize(RecyclableListV2 list, int minBlockSize, byte minBlockSizeBitShift, long newCapacity) + protected static long Resize(RecyclableLongListV2 list, int minBlockSize, byte minBlockSizeBitShift, long newCapacity) { ArrayPool blockArrayPool = list._blockArrayPool; int sourceBlockCount = checked((int)(list._capacity >> minBlockSizeBitShift)); @@ -1198,14 +1198,14 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - public static long EnsureCapacity(RecyclableListV2 list, long requestedCapacity) + public static long EnsureCapacity(RecyclableLongListV2 list, long requestedCapacity) { long newCapacity = list._capacity > 0 ? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity)) : requestedCapacity; int blockSize = list._blockSize; - newCapacity = RecyclableListV2.Resize(list, blockSize, list._blockSizePow2Shift, newCapacity); + newCapacity = RecyclableLongListV2.Resize(list, blockSize, list._blockSizePow2Shift, newCapacity); if (newCapacity > 0 && blockSize != list._memoryBlocks[0].Length) { blockSize = list._memoryBlocks[0].Length; @@ -1223,7 +1223,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveOptimization)] - public RecyclableListV2(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListV2(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -1262,7 +1262,7 @@ namespace Recyclable.Collections.Benchmarks.POC } } - public RecyclableListV2(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListV2(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) { memoryBlocksPool ??= _defaultMemoryBlocksPool; _memoryBlocksPool = memoryBlocksPool; @@ -1418,7 +1418,7 @@ namespace Recyclable.Collections.Benchmarks.POC _nextItemBlockIndex = targetBlockIndex; } - public void AddRange(RecyclableListV2 items) + public void AddRange(RecyclableLongListV2 items) { if (items.LongCount == 0) { @@ -1591,9 +1591,9 @@ namespace Recyclable.Collections.Benchmarks.POC public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.MinPooledArrayLength) { - if (source is RecyclableListV2 sourceRecyclableList) + if (source is RecyclableLongListV2 sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -1818,7 +1818,7 @@ namespace Recyclable.Collections.Benchmarks.POC IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableListV2() + ~RecyclableLongListV2() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); @@ -1842,9 +1842,9 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - #region RecyclableList v3 + #region RecyclableLongList v3 - internal class RecyclableListV3 : IDisposable, IList + internal class RecyclableLongListV3 : IDisposable, IList { private const int ItemNotFoundIndex = -1; @@ -1892,7 +1892,7 @@ namespace Recyclable.Collections.Benchmarks.POC public int NextItemIndex => _nextItemIndex; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - private static void CopyItems(RecyclableListV3 list, long index) + private static void CopyItems(RecyclableLongListV3 list, long index) { T[][] memoryBlocks = list._memoryBlocks; int nextItemIndex = list._nextItemIndex; @@ -2083,10 +2083,10 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// Creates a set of new memory buffers, if needed, to allow storing at minimum no. of items. /// - /// that needs to be resized. + /// that needs to be resized. /// Minimal requested block size. It MUST be rounded to the power of 2, see remarks. /// Pre-calculated bit shifting value for left & right shift operations against. - /// The minimum no. of items MUST be able to store after . + /// The minimum no. of items MUST be able to store after . /// /// For performance reasons, MUST a power of 2. This simplifies a lot block & item /// index calculations, i.e. makes them logical operations on bits. @@ -2095,7 +2095,7 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// The maximum no. of items can store. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static long Resize(RecyclableListV3 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) + protected static long Resize(RecyclableLongListV3 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) { ArrayPool blockArrayPool = list._blockArrayPool; int sourceBlockCount = list._reservedBlockCount; @@ -2170,7 +2170,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static void SetupBlockArrayPooling(RecyclableListV3 list, int blockSize, ArrayPool? blockArrayPool = null) + protected static void SetupBlockArrayPooling(RecyclableLongListV3 list, int blockSize, ArrayPool? blockArrayPool = null) { list._blockSize = blockSize; list._blockSizePow2Shift = (byte)(31 - BitOperations.LeadingZeroCount((uint)blockSize)); @@ -2187,7 +2187,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - protected static long EnsureCapacity(RecyclableListV3 list, long requestedCapacity) + protected static long EnsureCapacity(RecyclableLongListV3 list, long requestedCapacity) { long newCapacity = list._capacity > 0 ? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity)) @@ -2207,7 +2207,7 @@ namespace Recyclable.Collections.Benchmarks.POC [MethodImpl(MethodImplOptions.AggressiveOptimization)] #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListV3(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListV3(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -2236,7 +2236,7 @@ namespace Recyclable.Collections.Benchmarks.POC } #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListV3(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListV3(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -2379,7 +2379,7 @@ namespace Recyclable.Collections.Benchmarks.POC _nextItemBlockIndex = targetBlockIndex; } - public void AddRange(RecyclableListV3 items) + public void AddRange(RecyclableLongListV3 items) { if (items.LongCount == 0) { @@ -2552,9 +2552,9 @@ namespace Recyclable.Collections.Benchmarks.POC public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.BlockSize) { - if (source is RecyclableList sourceRecyclableList) + if (source is RecyclableLongList sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -2781,7 +2781,7 @@ namespace Recyclable.Collections.Benchmarks.POC IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableListV3() + ~RecyclableLongListV3() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); @@ -2805,53 +2805,53 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - public partial class RecyclableListPocBenchmarks + public partial class RecyclableLongListPocBenchmarks { - public void RecyclableList_EnsureCapacityV1_ByPowOf2() + public void RecyclableLongList_EnsureCapacityV1_ByPowOf2() { - using var list = new RecyclableListV1(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongListV1(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); DoNothing(_ensureCapacityV1Func.Invoke(list, new object[] { TestObjectCount })); } - public void RecyclableList_EnsureCapacityV2_ByPowOf2() + public void RecyclableLongList_EnsureCapacityV2_ByPowOf2() { - using var list = new RecyclableListV2(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongListV2(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); DoNothing(_ensureCapacityV2Func.Invoke(null, new object[] { list, TestObjectCount })); } - public void RecyclableList_EnsureCapacityV3_ByPowOf2() + public void RecyclableLongList_EnsureCapacityV3_ByPowOf2() { - using var list = new RecyclableListV3(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongListV3(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); DoNothing(_ensureCapacityV3Func.Invoke(null, new object[] { list, TestObjectCount })); } - public void RecyclableList_EnsureCapacity_ByPowOf2() + public void RecyclableLongList_EnsureCapacity_ByPowOf2() { - using var list = new RecyclableList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); + using var list = new RecyclableLongList(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount); DoNothing(_ensureCapacityNewFunc.Invoke(null, new object[] { list, TestObjectCount })); } - public void RecyclableList_EnsureCapacityV1_ByBlockSize() + public void RecyclableLongList_EnsureCapacityV1_ByBlockSize() { - using var list = new RecyclableListV1(); + using var list = new RecyclableLongListV1(); DoNothing(_ensureCapacityV1Func.Invoke(list, new object[] { TestObjectCount })); } - public void RecyclableList_EnsureCapacityV2_ByBlockSize() + public void RecyclableLongList_EnsureCapacityV2_ByBlockSize() { - using var list = new RecyclableListV2(); + using var list = new RecyclableLongListV2(); DoNothing(_ensureCapacityV2Func.Invoke(null, new object[] { list, TestObjectCount })); } - public void RecyclableList_EnsureCapacityV3_ByBlockSize() + public void RecyclableLongList_EnsureCapacityV3_ByBlockSize() { - using var list = new RecyclableListV3(); + using var list = new RecyclableLongListV3(); DoNothing(_ensureCapacityV3Func.Invoke(null, new object[] { list, TestObjectCount })); } - public void RecyclableList_EnsureCapacity_ByBlockSize() + public void RecyclableLongList_EnsureCapacity_ByBlockSize() { - using var list = new RecyclableList(); + using var list = new RecyclableLongList(); DoNothing(_ensureCapacityNewFunc.Invoke(null, new object[] { list, TestObjectCount })); } } diff --git a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.IndexOf.cs b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.IndexOf.cs similarity index 95% rename from Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.IndexOf.cs rename to Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.IndexOf.cs index a1ce342..0fbea0a 100644 --- a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.IndexOf.cs +++ b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.IndexOf.cs @@ -96,9 +96,9 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - #region RecyclableList IndexOf v1 + #region RecyclableLongList IndexOf v1 - internal class RecyclableListIndexOfV1 : IDisposable, IList + internal class RecyclableLongListIndexOfV1 : IDisposable, IList { private const int ItemNotFoundIndex = -1; private const double OptimalParallelSearchStep = 0.329; @@ -153,7 +153,7 @@ namespace Recyclable.Collections.Benchmarks.POC public int NextItemIndex => _nextItemIndex; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - private static void CopyItems(RecyclableListIndexOfV1 list, long index) + private static void CopyItems(RecyclableLongListIndexOfV1 list, long index) { T[][] memoryBlocks = list._memoryBlocks; int nextItemIndex = list._nextItemIndex; @@ -316,7 +316,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.AggressiveInlining)] - private static long DoLongIndexOfParallel(in RecyclableListIndexOfV1 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) + private static long DoLongIndexOfParallel(in RecyclableLongListIndexOfV1 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) { int blockSize = list._blockSize; int blockIndex = itemRange.BlockIndex; @@ -491,10 +491,10 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// Creates a set of new memory buffers, if needed, to allow storing at minimum no. of items. /// - /// that needs to be resized. + /// that needs to be resized. /// Minimal requested block size. It MUST be rounded to the power of 2, see remarks. /// Pre-calculated bit shifting value for left & right shift operations against. - /// The minimum no. of items MUST be able to store after . + /// The minimum no. of items MUST be able to store after . /// /// For performance reasons, MUST a power of 2. This simplifies a lot block & item /// index calculations, i.e. makes them logical operations on bits. @@ -507,7 +507,7 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// The maximum no. of items can store. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static long Resize(RecyclableListIndexOfV1 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) + protected static long Resize(RecyclableLongListIndexOfV1 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) { ArrayPool blockArrayPool = list._blockArrayPool; int sourceBlockCount = list._reservedBlockCount; @@ -594,7 +594,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static void SetupBlockArrayPooling(RecyclableListIndexOfV1 list, int blockSize, ArrayPool? blockArrayPool = null) + protected static void SetupBlockArrayPooling(RecyclableLongListIndexOfV1 list, int blockSize, ArrayPool? blockArrayPool = null) { list._blockSize = blockSize; list._blockSizePow2BitShift = (byte)(31 - BitOperations.LeadingZeroCount((uint)blockSize)); @@ -604,7 +604,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - protected static long EnsureCapacity(RecyclableListIndexOfV1 list, long requestedCapacity) + protected static long EnsureCapacity(RecyclableLongListIndexOfV1 list, long requestedCapacity) { long newCapacity = list._capacity > 0 ? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity)) @@ -624,7 +624,7 @@ namespace Recyclable.Collections.Benchmarks.POC [MethodImpl(MethodImplOptions.AggressiveOptimization)] #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV1(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV1(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -653,7 +653,7 @@ namespace Recyclable.Collections.Benchmarks.POC } #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV1(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV1(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -799,7 +799,7 @@ namespace Recyclable.Collections.Benchmarks.POC _nextItemBlockIndex = targetBlockIndex; } - public void AddRange(RecyclableListIndexOfV1 items) + public void AddRange(RecyclableLongListIndexOfV1 items) { if (items.LongCount == 0) { @@ -975,9 +975,9 @@ namespace Recyclable.Collections.Benchmarks.POC public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.BlockSize) { - if (source is RecyclableList sourceRecyclableList) + if (source is RecyclableLongList sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -1219,7 +1219,7 @@ namespace Recyclable.Collections.Benchmarks.POC IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableListIndexOfV1() + ~RecyclableLongListIndexOfV1() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); @@ -1243,9 +1243,9 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - #region RecyclableList IndexOf v2 + #region RecyclableLongList IndexOf v2 - internal class RecyclableListIndexOfV2 : IDisposable, IList + internal class RecyclableLongListIndexOfV2 : IDisposable, IList { private const int ItemNotFoundIndex = -1; private const double OptimalParallelSearchStep = 0.329; @@ -1300,7 +1300,7 @@ namespace Recyclable.Collections.Benchmarks.POC public int NextItemIndex => _nextItemIndex; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - private static void CopyItems(RecyclableListIndexOfV2 list, long index) + private static void CopyItems(RecyclableLongListIndexOfV2 list, long index) { T[][] memoryBlocks = list._memoryBlocks; int nextItemIndex = list._nextItemIndex; @@ -1463,7 +1463,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.AggressiveInlining)] - private static long DoLongIndexOfParallel(in RecyclableListIndexOfV2 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) + private static long DoLongIndexOfParallel(in RecyclableLongListIndexOfV2 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) { int blockSize = list._blockSize; int blockIndex = itemRange.BlockIndex; @@ -1636,10 +1636,10 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// Creates a set of new memory buffers, if needed, to allow storing at minimum no. of items. /// - /// that needs to be resized. + /// that needs to be resized. /// Minimal requested block size. It MUST be rounded to the power of 2, see remarks. /// Pre-calculated bit shifting value for left & right shift operations against. - /// The minimum no. of items MUST be able to store after . + /// The minimum no. of items MUST be able to store after . /// /// For performance reasons, MUST a power of 2. This simplifies a lot block & item /// index calculations, i.e. makes them logical operations on bits. @@ -1652,7 +1652,7 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// The maximum no. of items can store. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static long Resize(RecyclableListIndexOfV2 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) + protected static long Resize(RecyclableLongListIndexOfV2 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) { ArrayPool blockArrayPool = list._blockArrayPool; int sourceBlockCount = list._reservedBlockCount; @@ -1739,7 +1739,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static void SetupBlockArrayPooling(RecyclableListIndexOfV2 list, int blockSize, ArrayPool? blockArrayPool = null) + protected static void SetupBlockArrayPooling(RecyclableLongListIndexOfV2 list, int blockSize, ArrayPool? blockArrayPool = null) { list._blockSize = blockSize; list._blockSizePow2BitShift = (byte)(31 - BitOperations.LeadingZeroCount((uint)blockSize)); @@ -1749,7 +1749,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - protected static long EnsureCapacity(RecyclableListIndexOfV2 list, long requestedCapacity) + protected static long EnsureCapacity(RecyclableLongListIndexOfV2 list, long requestedCapacity) { long newCapacity = list._capacity > 0 ? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity)) @@ -1769,7 +1769,7 @@ namespace Recyclable.Collections.Benchmarks.POC [MethodImpl(MethodImplOptions.AggressiveOptimization)] #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV2(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV2(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -1798,7 +1798,7 @@ namespace Recyclable.Collections.Benchmarks.POC } #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV2(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV2(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -1944,7 +1944,7 @@ namespace Recyclable.Collections.Benchmarks.POC _nextItemBlockIndex = targetBlockIndex; } - public void AddRange(RecyclableListIndexOfV2 items) + public void AddRange(RecyclableLongListIndexOfV2 items) { if (items.LongCount == 0) { @@ -2120,9 +2120,9 @@ namespace Recyclable.Collections.Benchmarks.POC public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.BlockSize) { - if (source is RecyclableListIndexOfV2 sourceRecyclableList) + if (source is RecyclableLongListIndexOfV2 sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -2364,7 +2364,7 @@ namespace Recyclable.Collections.Benchmarks.POC IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableListIndexOfV2() + ~RecyclableLongListIndexOfV2() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); @@ -2388,9 +2388,9 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - #region RecyclableList IndexOf v3 + #region RecyclableLongList IndexOf v3 - internal class RecyclableListIndexOfV3 : IDisposable, IList + internal class RecyclableLongListIndexOfV3 : IDisposable, IList { private const long ItemNotFoundIndexLong = -1L; private const int ItemNotFoundIndex = -1; @@ -2446,7 +2446,7 @@ namespace Recyclable.Collections.Benchmarks.POC public int NextItemIndex => _nextItemIndex; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - private static void CopyItems(RecyclableListIndexOfV3 list, long index) + private static void CopyItems(RecyclableLongListIndexOfV3 list, long index) { T[][] memoryBlocks = list._memoryBlocks; int nextItemIndex = list._nextItemIndex; @@ -2608,7 +2608,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.AggressiveInlining)] - private static long DoLongIndexOfParallel(in RecyclableListIndexOfV3 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) + private static long DoLongIndexOfParallel(in RecyclableLongListIndexOfV3 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) { int blockSize = list._blockSize; int blockIndex = itemRange.BlockIndex; @@ -2753,10 +2753,10 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// Creates a set of new memory buffers, if needed, to allow storing at minimum no. of items. /// - /// that needs to be resized. + /// that needs to be resized. /// Minimal requested block size. It MUST be rounded to the power of 2, see remarks. /// Pre-calculated bit shifting value for left & right shift operations against. - /// The minimum no. of items MUST be able to store after . + /// The minimum no. of items MUST be able to store after . /// /// For performance reasons, MUST a power of 2. This simplifies a lot block & item /// index calculations, i.e. makes them logical operations on bits. @@ -2769,7 +2769,7 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// The maximum no. of items can store. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static long Resize(RecyclableListIndexOfV3 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) + protected static long Resize(RecyclableLongListIndexOfV3 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) { ArrayPool blockArrayPool = list._blockArrayPool; int sourceBlockCount = list._reservedBlockCount; @@ -2856,7 +2856,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static void SetupBlockArrayPooling(RecyclableListIndexOfV3 list, int blockSize, ArrayPool? blockArrayPool = null) + protected static void SetupBlockArrayPooling(RecyclableLongListIndexOfV3 list, int blockSize, ArrayPool? blockArrayPool = null) { list._blockSize = blockSize; list._blockSizePow2BitShift = (byte)(31 - BitOperations.LeadingZeroCount((uint)blockSize)); @@ -2866,7 +2866,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - protected static long EnsureCapacity(RecyclableListIndexOfV3 list, long requestedCapacity) + protected static long EnsureCapacity(RecyclableLongListIndexOfV3 list, long requestedCapacity) { long newCapacity = list._capacity > 0 ? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity)) @@ -2886,7 +2886,7 @@ namespace Recyclable.Collections.Benchmarks.POC [MethodImpl(MethodImplOptions.AggressiveOptimization)] #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV3(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV3(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -2915,7 +2915,7 @@ namespace Recyclable.Collections.Benchmarks.POC } #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV3(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV3(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -3061,7 +3061,7 @@ namespace Recyclable.Collections.Benchmarks.POC _nextItemBlockIndex = targetBlockIndex; } - public void AddRange(RecyclableListIndexOfV3 items) + public void AddRange(RecyclableLongListIndexOfV3 items) { if (items.LongCount == 0) { @@ -3237,9 +3237,9 @@ namespace Recyclable.Collections.Benchmarks.POC public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.BlockSize) { - if (source is RecyclableList sourceRecyclableList) + if (source is RecyclableLongList sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -3478,7 +3478,7 @@ namespace Recyclable.Collections.Benchmarks.POC IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableListIndexOfV3() + ~RecyclableLongListIndexOfV3() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); @@ -3502,15 +3502,15 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - #region RecyclableList IndexOf v4 + #region RecyclableLongList IndexOf v4 - internal static class RecyclableListIndexOfV4Extensions + internal static class RecyclableLongListIndexOfV4Extensions { private const long ItemNotFoundIndexLong = -1L; private const int ItemNotFoundIndex = -1; [MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.AggressiveInlining)] - public static long DoLongIndexOfParallel(this RecyclableListIndexOfV4 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) + public static long DoLongIndexOfParallel(this RecyclableLongListIndexOfV4 list, in ItemRangeV1 itemRange, in T itemToFind, in ManualResetEventSlimmer itemFoundSignal) { int blockSize = list._blockSize; int blockIndex = itemRange.BlockIndex; @@ -3583,7 +3583,7 @@ namespace Recyclable.Collections.Benchmarks.POC } } - internal class RecyclableListIndexOfV4 : IDisposable, IList + internal class RecyclableLongListIndexOfV4 : IDisposable, IList { private const long ItemNotFoundIndexLong = -1L; private const int ItemNotFoundIndex = -1; @@ -3639,7 +3639,7 @@ namespace Recyclable.Collections.Benchmarks.POC public int NextItemIndex => _nextItemIndex; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - private static void CopyItems(RecyclableListIndexOfV4 list, long index) + private static void CopyItems(RecyclableLongListIndexOfV4 list, long index) { T[][] memoryBlocks = list._memoryBlocks; int nextItemIndex = list._nextItemIndex; @@ -3817,7 +3817,7 @@ namespace Recyclable.Collections.Benchmarks.POC return ItemNotFoundIndexLong; } - private static bool ScheduleIndexOfTasks(ParallelSynchronizationContextV4 context, RecyclableListIndexOfV4 list, T itemToFind, ItemRangeV1 itemRange) + private static bool ScheduleIndexOfTasks(ParallelSynchronizationContextV4 context, RecyclableLongListIndexOfV4 list, T itemToFind, ItemRangeV1 itemRange) { _ = context.AllDoneSignal.AddParticipant(); _ = Task.Factory.StartNew(() => @@ -3845,7 +3845,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveOptimization | MethodImplOptions.NoInlining)] - public static void Iterate(in ParallelSynchronizationContextV4 context, RecyclableListIndexOfV4 list, in T itemToFind, Func, T, ItemRangeV1, bool> action) + public static void Iterate(in ParallelSynchronizationContextV4 context, RecyclableLongListIndexOfV4 list, in T itemToFind, Func, T, ItemRangeV1, bool> action) { int itemIndex = 0; ItemRangeV1 itemRange; @@ -3907,10 +3907,10 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// Creates a set of new memory buffers, if needed, to allow storing at minimum no. of items. /// - /// that needs to be resized. + /// that needs to be resized. /// Minimal requested block size. It MUST be rounded to the power of 2, see remarks. /// Pre-calculated bit shifting value for left & right shift operations against. - /// The minimum no. of items MUST be able to store after . + /// The minimum no. of items MUST be able to store after . /// /// For performance reasons, MUST a power of 2. This simplifies a lot block & item /// index calculations, i.e. makes them logical operations on bits. @@ -3923,7 +3923,7 @@ namespace Recyclable.Collections.Benchmarks.POC /// /// The maximum no. of items can store. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static long Resize(RecyclableListIndexOfV4 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) + protected static long Resize(RecyclableLongListIndexOfV4 list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) { ArrayPool blockArrayPool = list._blockArrayPool; int sourceBlockCount = list._reservedBlockCount; @@ -4010,7 +4010,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static void SetupBlockArrayPooling(RecyclableListIndexOfV4 list, int blockSize, ArrayPool? blockArrayPool = null) + protected static void SetupBlockArrayPooling(RecyclableLongListIndexOfV4 list, int blockSize, ArrayPool? blockArrayPool = null) { list._blockSize = blockSize; list._blockSizePow2BitShift = (byte)(31 - BitOperations.LeadingZeroCount((uint)blockSize)); @@ -4020,7 +4020,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - protected static long EnsureCapacity(RecyclableListIndexOfV4 list, long requestedCapacity) + protected static long EnsureCapacity(RecyclableLongListIndexOfV4 list, long requestedCapacity) { long newCapacity = list._capacity > 0 ? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity)) @@ -4040,7 +4040,7 @@ namespace Recyclable.Collections.Benchmarks.POC [MethodImpl(MethodImplOptions.AggressiveOptimization)] #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV4(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV4(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -4069,7 +4069,7 @@ namespace Recyclable.Collections.Benchmarks.POC } #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableListIndexOfV4(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongListIndexOfV4(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -4215,7 +4215,7 @@ namespace Recyclable.Collections.Benchmarks.POC _nextItemBlockIndex = targetBlockIndex; } - public void AddRange(RecyclableListIndexOfV4 items) + public void AddRange(RecyclableLongListIndexOfV4 items) { if (items.LongCount == 0) { @@ -4391,9 +4391,9 @@ namespace Recyclable.Collections.Benchmarks.POC public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.BlockSize) { - if (source is RecyclableList sourceRecyclableList) + if (source is RecyclableLongList sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -4632,7 +4632,7 @@ namespace Recyclable.Collections.Benchmarks.POC IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableListIndexOfV4() + ~RecyclableLongListIndexOfV4() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); @@ -4656,12 +4656,12 @@ namespace Recyclable.Collections.Benchmarks.POC #endregion - public partial class RecyclableListPocBenchmarks + public partial class RecyclableLongListPocBenchmarks { - public void RecyclableList_IndexOfV1() + public void RecyclableLongList_IndexOfV1() { var data = TestObjects; - var list = TestObjectsAsRecyclableListIndexOfV1; + var list = TestObjectsAsRecyclableLongListIndexOfV1; var dataCount = TestObjectCount; for (var i = 0; i < dataCount; i++) { @@ -4680,10 +4680,10 @@ namespace Recyclable.Collections.Benchmarks.POC } } - public void RecyclableList_IndexOfV2() + public void RecyclableLongList_IndexOfV2() { var data = TestObjects; - var list = TestObjectsAsRecyclableListIndexOfV2; + var list = TestObjectsAsRecyclableLongListIndexOfV2; var dataCount = TestObjectCount; for (var i = 0; i < dataCount; i++) { @@ -4691,10 +4691,10 @@ namespace Recyclable.Collections.Benchmarks.POC } } - public void RecyclableList_IndexOfV3() + public void RecyclableLongList_IndexOfV3() { var data = TestObjects; - var list = TestObjectsAsRecyclableListIndexOfV3; + var list = TestObjectsAsRecyclableLongListIndexOfV3; var dataCount = TestObjectCount; for (var i = 0; i < dataCount; i++) { @@ -4702,10 +4702,10 @@ namespace Recyclable.Collections.Benchmarks.POC } } - public void RecyclableList_IndexOfV4() + public void RecyclableLongList_IndexOfV4() { var data = TestObjects; - var list = TestObjectsAsRecyclableListIndexOfV4; + var list = TestObjectsAsRecyclableLongListIndexOfV4; var dataCount = TestObjectCount; for (var i = 0; i < dataCount; i++) { @@ -4713,10 +4713,10 @@ namespace Recyclable.Collections.Benchmarks.POC } } - public void RecyclableList_IndexOf() + public void RecyclableLongList_IndexOf() { var data = TestObjects; - var list = TestObjectsAsRecyclableList; + var list = TestObjectsAsRecyclableLongList; var dataCount = TestObjectCount; for (var i = 0; i < dataCount; i++) { diff --git a/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.cs b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.cs new file mode 100644 index 0000000..b24b1ef --- /dev/null +++ b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPoc.Benchmarks.cs @@ -0,0 +1,157 @@ +using System.Reflection; +using BenchmarkDotNet.Attributes; +using Collections.Pooled; +using Recyclable.Collections.Benchmarks.Core; + +namespace Recyclable.Collections.Benchmarks.POC +{ + public enum RecyclableLongListPocBenchmarkType + { + IndexOfV1, + IndexOfV2, + IndexOfV3, + IndexOfV4, + IndexOf_PooledList, + IndexOf, + EnsureCapacity_ByPowOf2, + EnsureCapacityV1_ByPowOf2, + EnsureCapacityV2_ByPowOf2, + EnsureCapacityV3_ByPowOf2, + } + + [MemoryDiagnoser] + public partial class RecyclableLongListPocBenchmarks : PocBenchmarkBase + { + [Params(RecyclableLongListPocBenchmarkType.IndexOf)] + public override RecyclableLongListPocBenchmarkType BenchmarkType { get => base.BenchmarkType; set => base.BenchmarkType = value; } + + // [Params(BenchmarkType.Array, BenchmarkType.List, BenchmarkType.RecyclableArrayList, BenchmarkType.RecyclableLongList)] + [Params(RecyclableLongListPocBenchmarkType.IndexOf_PooledList)] + public override RecyclableLongListPocBenchmarkType BaselineBenchmarkType { get => base.BaselineBenchmarkType; set => base.BaselineBenchmarkType = value; } + + private long[]? _testArray; + public long[] TestObjects => _testArray ?? throw new NullReferenceException("Something is wrong and test objects are null"); + + public RecyclableLongList TestObjectsAsRecyclableLongList => _testRecyclableLongList ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableLongList)} is null"); + private RecyclableLongListIndexOfV1? _testRecyclableLongListIndexOfV1; + internal RecyclableLongListIndexOfV1 TestObjectsAsRecyclableLongListIndexOfV1 => _testRecyclableLongListIndexOfV1 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableLongListIndexOfV1)} is null"); + private RecyclableLongListIndexOfV2? _testRecyclableLongListIndexOfV2; + private RecyclableLongList? _testRecyclableLongList; + internal RecyclableLongListIndexOfV2 TestObjectsAsRecyclableLongListIndexOfV2 => _testRecyclableLongListIndexOfV2 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableLongListIndexOfV2)} is null"); + private RecyclableLongListIndexOfV3? _testRecyclableLongListIndexOfV3; + internal RecyclableLongListIndexOfV3 TestObjectsAsRecyclableLongListIndexOfV3 => _testRecyclableLongListIndexOfV3 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableLongListIndexOfV3)} is null"); + private RecyclableLongListIndexOfV4? _testRecyclableLongListIndexOfV4; + internal RecyclableLongListIndexOfV4 TestObjectsAsRecyclableLongListIndexOfV4 => _testRecyclableLongListIndexOfV4 ?? throw new NullReferenceException($"Something is wrong and {nameof(RecyclableLongListIndexOfV4)} is null"); + private PooledList? _testPooledList; + internal PooledList TestPooledList => _testPooledList ?? throw new NullReferenceException($"Something is wrong and {nameof(PooledList)} is null"); + + private static readonly MethodInfo _ensureCapacityNewFunc; + private static readonly MethodInfo _ensureCapacityV1Func; + private static readonly MethodInfo _ensureCapacityV2Func; + private static readonly MethodInfo _ensureCapacityV3Func; + + static RecyclableLongListPocBenchmarks() + { + _ensureCapacityNewFunc = typeof(RecyclableLongList).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.NonPublic) + ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableLongList)}"); + + _ensureCapacityV1Func = typeof(RecyclableLongListV1).GetMethod("EnsureCapacity", BindingFlags.Instance | BindingFlags.NonPublic) + ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableLongListV1)}"); + + _ensureCapacityV2Func = typeof(RecyclableLongListV2).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.Public) + ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableLongListV2)}"); + + _ensureCapacityV3Func = typeof(RecyclableLongListV3).GetMethod("EnsureCapacity", BindingFlags.Static | BindingFlags.NonPublic) + ?? throw new NullReferenceException($"Method EnsureCapacity not found in class {nameof(RecyclableLongListV3)}"); + } + + public static void Run() + { + var benchmark = new RecyclableLongListPocBenchmarks(); + benchmark.Setup(); + // benchmark.RecyclableLongList_EnsureCapacity_ByPowOf2(); + // benchmark.RecyclableLongList_EnsureCapacityV1_ByPowOf2(); + // benchmark.RecyclableLongList_EnsureCapacityV2_ByPowOf2(); + // benchmark.RecyclableLongList_EnsureCapacityV3_ByPowOf2(); + // benchmark.RecyclableLongList_EnsureCapacity_ByBlockSize(); + // benchmark.RecyclableLongList_EnsureCapacityV1_ByBlockSize(); + // benchmark.RecyclableLongList_EnsureCapacityV2_ByBlockSize(); + // benchmark.RecyclableLongList_EnsureCapacityV3_ByBlockSize(); + benchmark.RecyclableLongList_IndexOf(); + benchmark.RecyclableLongList_IndexOfV1(); + benchmark.RecyclableLongList_IndexOfV2(); + benchmark.RecyclableLongList_IndexOfV3(); + benchmark.RecyclableLongList_IndexOfV4(); + benchmark.Cleanup(); + } + + public override void Setup() + { + Console.WriteLine("******* SETTING UP EXPECTED RESULTS DATA *******"); + _testArray = DataGenerator.EnumerateTestObjects(TestObjectCount); + + base.Setup(); + } + + public override void Cleanup() + { + _testArray = null; + _testRecyclableLongList?.Dispose(); + _testRecyclableLongList = null; + _testRecyclableLongListIndexOfV1?.Dispose(); + _testRecyclableLongListIndexOfV1 = null; + _testRecyclableLongListIndexOfV2?.Dispose(); + _testRecyclableLongListIndexOfV2 = null; + _testRecyclableLongListIndexOfV3?.Dispose(); + _testRecyclableLongListIndexOfV3 = null; + _testRecyclableLongListIndexOfV4?.Dispose(); + _testRecyclableLongListIndexOfV4 = null; + _testPooledList?.Dispose(); + _testPooledList = null; + + base.Cleanup(); + } + + protected override Action? GetTestMethod(RecyclableLongListPocBenchmarkType benchmarkType) => benchmarkType switch + { + RecyclableLongListPocBenchmarkType.IndexOfV1 => () => RecyclableLongList_IndexOfV1(), + RecyclableLongListPocBenchmarkType.IndexOfV2 => () => RecyclableLongList_IndexOfV2(), + RecyclableLongListPocBenchmarkType.IndexOfV3 => () => RecyclableLongList_IndexOfV3(), + RecyclableLongListPocBenchmarkType.IndexOfV4 => () => RecyclableLongList_IndexOfV4(), + RecyclableLongListPocBenchmarkType.IndexOf_PooledList => () => PooledList_IndexOf(), + RecyclableLongListPocBenchmarkType.IndexOf => () => RecyclableLongList_IndexOf(), + RecyclableLongListPocBenchmarkType.EnsureCapacity_ByPowOf2 => () => RecyclableLongList_EnsureCapacity_ByPowOf2(), + RecyclableLongListPocBenchmarkType.EnsureCapacityV1_ByPowOf2 => () => RecyclableLongList_EnsureCapacityV1_ByPowOf2(), + RecyclableLongListPocBenchmarkType.EnsureCapacityV2_ByPowOf2 => () => RecyclableLongList_EnsureCapacityV2_ByPowOf2(), + RecyclableLongListPocBenchmarkType.EnsureCapacityV3_ByPowOf2 => () => RecyclableLongList_EnsureCapacityV3_ByPowOf2(), + _ => throw CreateUnknownBenchmarkTypeException(benchmarkType), + }; + + protected override void PrepareData(T benchmarkType) + { + base.PrepareData(benchmarkType); + + switch (BenchmarkType) + { + case RecyclableLongListPocBenchmarkType.IndexOfV1: + _testRecyclableLongListIndexOfV1 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); + break; + case RecyclableLongListPocBenchmarkType.IndexOfV2: + _testRecyclableLongListIndexOfV2 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); + break; + case RecyclableLongListPocBenchmarkType.IndexOfV3: + _testRecyclableLongListIndexOfV3 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); + break; + case RecyclableLongListPocBenchmarkType.IndexOfV4: + _testRecyclableLongListIndexOfV4 = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); + break; + case RecyclableLongListPocBenchmarkType.IndexOf_PooledList: + _testPooledList = new PooledList(TestObjects, ClearMode.Auto); + break; + case RecyclableLongListPocBenchmarkType.IndexOf: + _testRecyclableLongList = new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); + break; + } + } + } +} diff --git a/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPos.Benchmarks.IndexOf.txt b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPos.Benchmarks.IndexOf.txt new file mode 100644 index 0000000..d4413b6 --- /dev/null +++ b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListPos.Benchmarks.IndexOf.txt @@ -0,0 +1,26 @@ +BenchmarkDotNet=v0.13.3, OS=ubuntu 20.04 +Intel Xeon Platinum 8272CL CPU 2.60GHz, 1 CPU, 4 logical and 2 physical cores +.NET SDK=7.0.203 + [Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2 + DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2 + + +| Method | Mean | Error | StdDev | Ratio | RatioSD | +|------------------------- |--------:|---------:|---------:|------:|--------:| +| RecyclableLongList_IndexOfV1 | 2.274 s | 0.0447 s | 0.0894 s | 1.00 | 0.04 | +| RecyclableLongList_IndexOfV2 | 2.302 s | 0.0456 s | 0.0750 s | 1.00 | 0.00 | +| RecyclableLongList_IndexOf | 2.234 s | 0.0446 s | 0.0681 s | 0.97 | 0.05 | + +// * Hints * +Outliers + RecyclableLongListPocBenchmarks.RecyclableLongList_IndexOfV2: Default -> 2 outliers were removed (2.54 s, 2.56 s) + RecyclableLongListPocBenchmarks.RecyclableLongList_IndexOf: Default -> 1 outlier was detected (2.06 s) + +// * Legends * + Mean : Arithmetic mean of all measurements + Error : Half of 99.9% confidence interval + StdDev : Standard deviation of all measurements + Ratio : Mean of the ratio distribution ([Current]/[Baseline]) + RatioSD : Standard deviation of the ratio distribution ([Current]/[Baseline]) + 1 s : 1 Second (1 sec) + diff --git a/Recyclable.Collections.Benchmarks/POC/WhenParallelSearchBenchmarks.cs b/Recyclable.Collections.Benchmarks/POC/WhenParallelSearchBenchmarks.cs index 683dcdf..b2b3e4a 100644 --- a/Recyclable.Collections.Benchmarks/POC/WhenParallelSearchBenchmarks.cs +++ b/Recyclable.Collections.Benchmarks/POC/WhenParallelSearchBenchmarks.cs @@ -78,7 +78,7 @@ namespace Recyclable.Collections.Benchmarks.POC //[Params(329_000, 512_000, 750_000, 1_000_000, 3_290_000)] //public int Step { get; set; } = 329_000; // This was the fastest so far - private RecyclableList? _testData; + private RecyclableLongList? _testData; public object? ItemToFind { get; set; } @@ -123,7 +123,7 @@ namespace Recyclable.Collections.Benchmarks.POC } [MethodImpl(MethodImplOptions.AggressiveOptimization)] - private static long DoLongIndexOfParallel(RecyclableList list, in long itemToFind, ItemRangeV2 searchInfo, ManualResetEventSlim itemFoundSignal) + private static long DoLongIndexOfParallel(RecyclableLongList list, in long itemToFind, ItemRangeV2 searchInfo, ManualResetEventSlim itemFoundSignal) { int index; int blockSize = list.BlockSize; @@ -300,7 +300,7 @@ namespace Recyclable.Collections.Benchmarks.POC { base.PrepareData(benchmarkType); - _testData ??= Enumerable.Range(1, TestObjectCount).Cast().ToRecyclableList(BlockSize); + _testData ??= Enumerable.Range(1, TestObjectCount).Cast().ToRecyclableLongList(BlockSize); ItemToFind ??= _testData.Last(); } diff --git a/Recyclable.Collections.Benchmarks/Program.cs b/Recyclable.Collections.Benchmarks/Program.cs index a835447..3c05b5f 100644 --- a/Recyclable.Collections.Benchmarks/Program.cs +++ b/Recyclable.Collections.Benchmarks/Program.cs @@ -27,8 +27,8 @@ internal class Program //foreach (var _ in Enumerable.Range(1, 1000)) //{ - //benchmark.RecyclableList_Remove_FirstItems(); - //benchmark.RecyclableList_RemoveAt_LastItems(); + //benchmark.RecyclableLongList_Remove_FirstItems(); + //benchmark.RecyclableLongList_RemoveAt_LastItems(); //benchmark.List_RemoveAt_LastItems(); //} @@ -40,7 +40,7 @@ internal class Program _ = BenchmarkRunner.Run(BenchmarkConfig); _ = BenchmarkRunner.Run(BenchmarkConfig); _ = BenchmarkRunner.Run(BenchmarkConfig); - _ = BenchmarkRunner.Run(BenchmarkConfig); + _ = BenchmarkRunner.Run(BenchmarkConfig); _ = BenchmarkRunner.Run(BenchmarkConfig); _ = BenchmarkRunner.Run(BenchmarkConfig); _ = BenchmarkRunner.Run(BenchmarkConfig); diff --git a/Recyclable.Collections.Benchmarks/RecyclableBenchmarkBase.cs b/Recyclable.Collections.Benchmarks/RecyclableBenchmarkBase.cs index 01d2bf7..abeb9a8 100644 --- a/Recyclable.Collections.Benchmarks/RecyclableBenchmarkBase.cs +++ b/Recyclable.Collections.Benchmarks/RecyclableBenchmarkBase.cs @@ -12,7 +12,7 @@ namespace Recyclable.Collections.Benchmarks List, PooledList, RecyclableArrayList, - RecyclableList, + RecyclableLongList, } [MemoryDiagnoser] @@ -28,8 +28,8 @@ namespace Recyclable.Collections.Benchmarks public PooledList TestObjectsAsPooledList => _testObjectsAsPooledList ?? throw new NullReferenceException("Something is wrong 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 RecyclableLongList? _testObjectsAsRecyclableLongList; + protected RecyclableLongList TestObjectsAsRecyclableLongList => _testObjectsAsRecyclableLongList ?? throw new NullReferenceException("Something is wrong and the field is not initialized"); protected IEnumerable TestObjectsAsIEnumerable { get @@ -68,8 +68,8 @@ namespace Recyclable.Collections.Benchmarks _testObjectsAsRecyclableArrayList ??= new(TestObjects, initialCapacity: TestObjectCount); break; - case RecyclableCollectionsBenchmarkSource.RecyclableList: - _testObjectsAsRecyclableList ??= new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); + case RecyclableCollectionsBenchmarkSource.RecyclableLongList: + _testObjectsAsRecyclableLongList ??= new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount); break; default: @@ -94,8 +94,8 @@ namespace Recyclable.Collections.Benchmarks _testObjectsAsPooledList = default; _testObjectsAsRecyclableArrayList?.Dispose(); _testObjectsAsRecyclableArrayList = default; - _testObjectsAsRecyclableList?.Dispose(); - _testObjectsAsRecyclableList = default; + _testObjectsAsRecyclableLongList?.Dispose(); + _testObjectsAsRecyclableLongList = default; base.Cleanup(); } } @@ -123,11 +123,11 @@ namespace Recyclable.Collections.Benchmarks // } // [Benchmark(Baseline = true)] - // public void RecyclableList() + // public void RecyclableLongList() // { // var data = TestObjects; // long dataCount = TestObjectCount; - // using var list = new RecyclableList(BlockSize, totalItemsCount: dataCount); + // using var list = new RecyclableLongList(BlockSize, totalItemsCount: dataCount); // for (long i = 0; i < dataCount; i++) // { // list.Add(data[i]); diff --git a/Recyclable.Collections.Benchmarks/Results/AllInOneBenchmarks.txt b/Recyclable.Collections.Benchmarks/Results/AllInOneBenchmarks.txt index bf3a53a..a2f956e 100644 --- a/Recyclable.Collections.Benchmarks/Results/AllInOneBenchmarks.txt +++ b/Recyclable.Collections.Benchmarks/Results/AllInOneBenchmarks.txt @@ -8,115 +8,115 @@ | List_Create_WithCapacity | 2,377.6 us | 43.03 us | 40.25 us | 1.93 | 0.03 | 54.6875 | 54.6875 | 54.6875 | 8000451 B | 137,938.81 | | PooledList_Create_WithCapacity | 1,229.4 us | 10.70 us | 9.48 us | 1.00 | 0.00 | - | - | - | 58 B | 1.00 | | RecyclableArrayList_Create_WithCapacity | 1,233.9 us | 3.93 us | 3.68 us | 1.00 | 0.01 | - | - | - | 41 B | 0.71 | -| RecyclableList_Create_WithCapacity | 786.5 us | 2.32 us | 1.94 us | 0.64 | 0.01 | - | - | - | 425 B | 7.33 | +| RecyclableLongList_Create_WithCapacity | 786.5 us | 2.32 us | 1.94 us | 0.64 | 0.01 | - | - | - | 425 B | 7.33 | | List_Create | 3.5523 ns | 0.0181 ns | 0.0141 ns | 3.5476 ns | 0.000 | 0.00 | 0.0153 | - | - | 32 B | 0.000 | | PooledList_Create | 6.9236 ns | 0.0110 ns | 0.0098 ns | 6.9222 ns | 0.000 | 0.00 | 0.0268 | - | - | 56 B | 0.000 | | RecyclableArrayList_Create | 4.6451 ns | 0.0063 ns | 0.0053 ns | 4.6457 ns | 0.000 | 0.00 | 0.0191 | - | - | 40 B | 0.000 | -| RecyclableList_Create | 212.8164 ns | 11.9841 ns | 35.3355 ns | 213.2258 ns | 0.000 | 0.00 | 0.0381 | 0.0379 | - | 80 B | 0.000 | +| RecyclableLongList_Create | 212.8164 ns | 11.9841 ns | 35.3355 ns | 213.2258 ns | 0.000 | 0.00 | 0.0381 | 0.0379 | - | 80 B | 0.000 | Array_GetItem | 239.7 us | 0.36 us | 0.32 us | 0.66 | 0.00 | - | NA | List_GetItem | 363.5 us | 0.67 us | 0.56 us | 1.00 | 0.00 | - | NA | PooledList_GetItem | 365.3 us | 0.90 us | 0.75 us | 1.00 | 0.00 | - | NA | RecyclableArrayList_GetItem | 239.2 us | 0.07 us | 0.06 us | 0.65 | 0.00 | - | NA | - RecyclableList_GetItem | 538.0 us | 1.01 us | 0.89 us | 1.47 | 0.00 | 1 B | NA | - RecyclableList_GetItem_AsSpan | 673.5 us | 4.85 us | 4.30 us | 1.84 | 0.01 | 1 B | NA | - RecyclableList_GetItem_AsArray | 239.4 us | 0.22 us | 0.20 us | 0.66 | 0.00 | - | NA | - RecyclableList_GetItem_AsForEach | 5,514.6 us | 27.28 us | 22.78 us | 15.10 | 0.06 | 109 B | NA | - RecyclableList_GetItem_AsWhile | 459.3 us | 0.38 us | 0.34 us | 1.26 | 0.00 | - | NA | + RecyclableLongList_GetItem | 538.0 us | 1.01 us | 0.89 us | 1.47 | 0.00 | 1 B | NA | + RecyclableLongList_GetItem_AsSpan | 673.5 us | 4.85 us | 4.30 us | 1.84 | 0.01 | 1 B | NA | + RecyclableLongList_GetItem_AsArray | 239.4 us | 0.22 us | 0.20 us | 0.66 | 0.00 | - | NA | + RecyclableLongList_GetItem_AsForEach | 5,514.6 us | 27.28 us | 22.78 us | 15.10 | 0.06 | 109 B | NA | + RecyclableLongList_GetItem_AsWhile | 459.3 us | 0.38 us | 0.34 us | 1.26 | 0.00 | - | NA | | Array_SetItem | 2,576,086.8389 ns | 13,880.4584 ns | 11,590.8114 ns | 2,576,978.1250 ns | 2.194 | 0.01 | - | - | - | 2 B | 0.000 | | List_SetItem | 3,361,745.7734 ns | 98,390.1277 ns | 290,105.5114 ns | 3,505,120.8984 ns | 2.771 | 0.29 | - | - | - | 2 B | 0.000 | | PooledList_SetItem | 2,676,757.7524 ns | 1,228.8178 ns | 1,026.1185 ns | 2,676,991.4062 ns | 2.280 | 0.01 | - | - | - | 2 B | 0.000 | | RecyclableArrayList_SetItem | 2,547,059.6540 ns | 9,002.9953 ns | 7,980.9208 ns | 2,542,056.8359 ns | 2.170 | 0.01 | - | - | - | 2 B | 0.000 | -| RecyclableList_SetItem | 2,326,771.9866 ns | 3,186.0942 ns | 2,824.3895 ns | 2,326,636.7188 ns | 1.981 | 0.01 | - | - | - | 2 B | 0.000 | +| RecyclableLongList_SetItem | 2,326,771.9866 ns | 3,186.0942 ns | 2,824.3895 ns | 2,326,636.7188 ns | 1.981 | 0.01 | - | - | - | 2 B | 0.000 | | Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Gen2 | Allocated | Alloc Ratio | |------------------------------------------------------------ |----------:|----------:|----------:|------:|--------:|---------:|--------:|--------:|-----------:|------------:| | List_Add | 11.002 ms | 0.2189 ms | 0.2996 ms | 1.36 | 0.04 | 140.6250 | 93.7500 | 93.7500 | 16778117 B | 236,311.51 | | PooledList_Add | 8.117 ms | 0.0115 ms | 0.0102 ms | 1.00 | 0.00 | - | - | - | 71 B | 1.00 | | RecyclableArrayList_Add | 8.771 ms | 0.0169 ms | 0.0141 ms | 1.08 | 0.00 | - | - | - | 1233 B | 17.37 | -| RecyclableList_Add | 6.024 ms | 0.1101 ms | 0.1030 ms | 0.74 | 0.01 | - | - | - | 3317 B | 46.72 | +| RecyclableLongList_Add | 6.024 ms | 0.1101 ms | 0.1030 ms | 0.74 | 0.01 | - | - | - | 3317 B | 46.72 | | List_Add_WithCapacity | 3,724,682.0668 ns | 88,719.4866 ns | 260,198.8962 ns | 3,717,873.0469 ns | 3.326 | 0.09 | 50.7813 | 50.7813 | 50.7813 | 4000368 B | 1.000 | | PooledList_Add_WithCapacity | 2,575,618.8337 ns | 5,277.9410 ns | 4,678.7572 ns | 2,575,805.2734 ns | 2.194 | 0.01 | - | - | - | 60 B | 0.000 | | RecyclableArrayList_Add_WithCapacity | 2,785,606.2500 ns | 4,595.4354 ns | 4,073.7338 ns | 2,785,292.7734 ns | 2.372 | 0.01 | - | - | - | 42 B | 0.000 | -| RecyclableList_Add_WithCapacity | 2,878,685.9701 ns | 44,974.7609 ns | 35,113.3350 ns | 2,873,102.9297 ns | 2.453 | 0.03 | - | - | - | 170 B | 0.000 | +| RecyclableLongList_Add_WithCapacity | 2,878,685.9701 ns | 44,974.7609 ns | 35,113.3350 ns | 2,873,102.9297 ns | 2.453 | 0.03 | - | - | - | 170 B | 0.000 | | List_AddRangeWhenSourceIsArray | 1,966,607.1581 ns | 39,075.4380 ns | 100,165.2861 ns | 1,958,457.4219 ns | 1.721 | 0.07 | 42.9688 | 42.9688 | 42.9688 | 4000364 B | 1.000 | | PooledList_AddRangeWhenSourceIsArray | 972,973.4049 ns | 12,365.6121 ns | 11,566.8012 ns | 974,744.8242 ns | 0.829 | 0.01 | - | - | - | 57 B | 0.000 | | RecyclableArrayList_AddRangeWhenSourceIsArray | 1,098,651.7578 ns | 3,202.7829 ns | 2,995.8851 ns | 1,097,979.4922 ns | 0.936 | 0.00 | - | - | - | 41 B | 0.000 | -| RecyclableList_AddRangeWhenSourceIsArray | 1,023,799.0234 ns | 2,772.1984 ns | 2,457.4816 ns | 1,023,618.7500 ns | 0.872 | 0.00 | - | - | - | 169 B | 0.000 | +| RecyclableLongList_AddRangeWhenSourceIsArray | 1,023,799.0234 ns | 2,772.1984 ns | 2,457.4816 ns | 1,023,618.7500 ns | 0.872 | 0.00 | - | - | - | 169 B | 0.000 | | List_AddRangeWhenSourceIsList | 1,954,805.9462 ns | 37,631.3829 ns | 71,597.6170 ns | 1,947,531.6406 ns | 1.656 | 0.06 | 42.9688 | 42.9688 | 42.9688 | 4000363 B | 1.000 | | PooledList_AddRangeWhenSourceIsList | 963,657.7116 ns | 5,594.8195 ns | 5,233.3976 ns | 965,055.4199 ns | 0.820 | 0.01 | - | - | - | 57 B | 0.000 | | RecyclableArrayList_AddRangeWhenSourceIsList | 1,114,697.8385 ns | 4,015.8164 ns | 3,756.3971 ns | 1,115,863.6719 ns | 0.950 | 0.00 | - | - | - | 41 B | 0.000 | -| RecyclableList_AddRangeWhenSourceIsList | 1,008,424.0374 ns | 2,179.7502 ns | 1,932.2918 ns | 1,008,779.8828 ns | 0.859 | 0.00 | - | - | - | 169 B | 0.000 | +| RecyclableLongList_AddRangeWhenSourceIsList | 1,008,424.0374 ns | 2,179.7502 ns | 1,932.2918 ns | 1,008,779.8828 ns | 0.859 | 0.00 | - | - | - | 169 B | 0.000 | | List_AddRangeWhenSourceIsIList | 2,045,453.8895 ns | 40,653.4327 ns | 98,956.0738 ns | 2,040,041.7969 ns | 1.734 | 0.12 | 42.9688 | 42.9688 | 42.9688 | 4000366 B | 1.000 | | PooledList_AddRangeWhenSourceIsIList | 977,402.4790 ns | 4,165.1933 ns | 3,478.1251 ns | 978,420.3125 ns | 0.832 | 0.00 | - | - | - | 58 B | 0.000 | | RecyclableArrayList_AddRangeWhenSourceIsIList | 1,109,563.8477 ns | 4,480.2733 ns | 4,190.8505 ns | 1,108,281.9336 ns | 0.945 | 0.00 | - | - | - | 41 B | 0.000 | -| RecyclableList_AddRangeWhenSourceIsIList | 2,632,797.0052 ns | 3,899.2563 ns | 3,044.2828 ns | 2,632,267.1875 ns | 2.243 | 0.01 | - | - | - | 170 B | 0.000 | +| RecyclableLongList_AddRangeWhenSourceIsIList | 2,632,797.0052 ns | 3,899.2563 ns | 3,044.2828 ns | 2,632,267.1875 ns | 2.243 | 0.01 | - | - | - | 170 B | 0.000 | | PooledList_AddRangeWhenSourceIsIEnumerable | 28,102,425.4630 ns | 556,294.1092 ns | 779,846.6478 ns | 28,009,543.7500 ns | 24.007 | 0.74 | 2187.5000 | 1375.0000 | 218.7500 | 12000526 B | 3.000 | | List_AddRangeWhenSourceIsIEnumerable | 47,884,030.8442 ns | 955,391.3313 ns | 1,370,193.6989 ns | 48,152,172.7273 ns | 40.578 | 1.04 | 2272.7273 | 1363.6364 | 363.6364 | 20389288 B | 5.097 | | RecyclableArrayList_AddRangeWhenSourceIsIEnumerable | 27,102,237.2533 ns | 535,598.7947 ns | 595,316.6412 ns | 27,248,382.8125 ns | 23.009 | 0.61 | 2250.0000 | 1406.2500 | 250.0000 | 12000305 B | 3.000 | -| RecyclableList_AddRangeWhenSourceIsIEnumerable | 27,206,882.1023 ns | 517,997.7196 ns | 636,147.7188 ns | 27,262,153.1250 ns | 23.049 | 0.64 | 2218.7500 | 1468.7500 | 250.0000 | 12000361 B | 3.000 | +| RecyclableLongList_AddRangeWhenSourceIsIEnumerable | 27,206,882.1023 ns | 517,997.7196 ns | 636,147.7188 ns | 27,262,153.1250 ns | 23.049 | 0.64 | 2218.7500 | 1468.7500 | 250.0000 | 12000361 B | 3.000 | | PooledList_AddRangeWhenSourceIsPooledList | 958,132.3033 ns | 4,444.5508 ns | 3,939.9785 ns | 957,355.9570 ns | 0.816 | 0.00 | - | - | - | 57 B | 0.000 | | RecyclableArrayList_AddRangeWhenSourceIsRecyclableArrayList | 1,068,135.4492 ns | 15,036.9473 ns | 12,556.5320 ns | 1,063,337.2070 ns | 0.910 | 0.01 | - | - | - | 41 B | 0.000 | -| RecyclableList_AddRangeWhenSourceIsRecyclableArrayList | 1,057,253.7249 ns | 2,697.5224 ns | 2,391.2834 ns | 1,057,475.9766 ns | 0.901 | 0.00 | - | - | - | 169 B | 0.000 | +| RecyclableLongList_AddRangeWhenSourceIsRecyclableArrayList | 1,057,253.7249 ns | 2,697.5224 ns | 2,391.2834 ns | 1,057,475.9766 ns | 0.901 | 0.00 | - | - | - | 169 B | 0.000 | | List_AddRange_WithCapacity | 2,022,247.3039 ns | 44,489.4467 ns | 129,071.9520 ns | 2,030,418.9453 ns | 1.767 | 0.06 | 39.0625 | 39.0625 | 39.0625 | 4000318 B | 1.000 | | PooledList_AddRange_WithCapacity | 965,635.9570 ns | 11,740.2154 ns | 10,981.8048 ns | 968,593.2617 ns | 0.822 | 0.01 | - | - | - | 57 B | 0.000 | | RecyclableArrayList_AddRange_WithCapacity | 1,044,438.5517 ns | 3,047.5353 ns | 2,544.8300 ns | 1,045,038.8672 ns | 0.890 | 0.00 | - | - | - | 41 B | 0.000 | -| RecyclableList_AddRange_WithCapacity | 1,028,953.5156 ns | 17,735.8499 ns | 14,810.2379 ns | 1,022,104.4922 ns | 0.876 | 0.01 | - | - | - | 169 B | 0.000 | +| RecyclableLongList_AddRange_WithCapacity | 1,028,953.5156 ns | 17,735.8499 ns | 14,810.2379 ns | 1,022,104.4922 ns | 0.876 | 0.01 | - | - | - | 169 B | 0.000 | | Array_Count | 0.0087 ns | 0.0110 ns | 0.0103 ns | 0.0024 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | | List_Count | 1.2190 ns | 0.0046 ns | 0.0040 ns | 1.2173 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | | PooledList_Count | 0.0037 ns | 0.0015 ns | 0.0012 ns | 0.0040 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | | RecyclableArrayList_Count | 1.2096 ns | 0.0009 ns | 0.0008 ns | 1.2092 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | -| RecyclableList_Count | 0.0103 ns | 0.0008 ns | 0.0007 ns | 0.0102 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | +| RecyclableLongList_Count | 0.0103 ns | 0.0008 ns | 0.0007 ns | 0.0102 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | | Array_LongCount | 0.0021 ns | 0.0005 ns | 0.0004 ns | 0.0022 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | -| RecyclableList_LongCount | 0.0030 ns | 0.0004 ns | 0.0003 ns | 0.0031 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | +| RecyclableLongList_LongCount | 0.0030 ns | 0.0004 ns | 0.0003 ns | 0.0031 ns | 0.000 | 0.00 | - | - | - | - | 0.000 | | List_Contains_FirstItems | 1,855,720,661.5385 ns | 16,632,292.4881 ns | 13,888,717.5079 ns | 1,850,307,400.0000 ns | 1,580.480 | 10.24 | - | - | - | 600 B | 0.000 | | PooledList_Contains_FirstItems | 1,854,542,814.2857 ns | 3,151,361.3032 ns | 2,793,599.7119 ns | 1,855,147,650.0000 ns | 1,579.345 | 5.84 | - | - | - | 600 B | 0.000 | -| RecyclableList_Contains_FirstItems | 1,842,715,553.8462 ns | 5,837,438.3043 ns | 4,874,525.3630 ns | 1,840,917,300.0000 ns | 1,569.420 | 6.23 | - | - | - | 600 B | 0.000 | +| RecyclableLongList_Contains_FirstItems | 1,842,715,553.8462 ns | 5,837,438.3043 ns | 4,874,525.3630 ns | 1,840,917,300.0000 ns | 1,569.420 | 6.23 | - | - | - | 600 B | 0.000 | | List_Contains_LastItems | 56,934,350,853.3333 ns | 257,718,254.2389 ns | 241,069,814.9149 ns | 56,884,611,800.0000 ns | 48,516.143 | 270.39 | - | - | - | 600 B | 0.000 | | PooledList_Contains_LastItems | 57,262,565,633.3333 ns | 295,685,051.7358 ns | 276,583,980.8497 ns | 57,246,796,900.0000 ns | 48,801.131 | 237.64 | - | - | - | 600 B | 0.000 | -| RecyclableList_Contains_LastItems | 57,019,747,564.2857 ns | 264,241,719.1753 ns | 234,243,401.3552 ns | 57,059,345,900.0000 ns | 48,552.402 | 223.09 | - | - | - | 600 B | 0.000 | +| RecyclableLongList_Contains_LastItems | 57,019,747,564.2857 ns | 264,241,719.1753 ns | 234,243,401.3552 ns | 57,059,345,900.0000 ns | 48,552.402 | 223.09 | - | - | - | 600 B | 0.000 | | Array_IndexOf_FirstItems | 1,874,810,260.0000 ns | 25,774,115.5271 ns | 24,109,123.6555 ns | 1,867,388,700.0000 ns | 1,597.521 | 22.54 | - | - | - | 600 B | 0.000 | | List_IndexOf_FirstItems | 1,864,704,725.0000 ns | 10,982,470.8154 ns | 8,574,390.8164 ns | 1,866,253,200.0000 ns | 1,588.702 | 10.94 | - | - | - | 600 B | 0.000 | | PooledList_IndexOf_FirstItems | 1,840,856,800.0000 ns | 4,046,589.8784 ns | 3,159,311.2037 ns | 1,839,944,050.0000 ns | 1,568.374 | 6.17 | - | - | - | 600 B | 0.000 | | RecyclableArrayList_IndexOf_FirstItems | 1,832,934,950.0000 ns | 1,729,308.0131 ns | 1,350,129.9476 ns | 1,832,475,300.0000 ns | 1,561.625 | 5.52 | - | - | - | 600 B | 0.000 | -| RecyclableList_IndexOf_FirstItems | 1,844,986,792.3077 ns | 3,209,050.1952 ns | 2,679,702.2516 ns | 1,843,943,600.0000 ns | 1,571.359 | 6.49 | - | - | - | 600 B | 0.000 | -| RecyclableList_LongIndexOf_FirstItems | 1,878,933,500.0000 ns | 17,118,131.6171 ns | 16,012,310.9355 ns | 1,870,009,600.0000 ns | 1,601.616 | 14.82 | - | - | - | 600 B | 0.000 | +| RecyclableLongList_IndexOf_FirstItems | 1,844,986,792.3077 ns | 3,209,050.1952 ns | 2,679,702.2516 ns | 1,843,943,600.0000 ns | 1,571.359 | 6.49 | - | - | - | 600 B | 0.000 | +| RecyclableLongList_LongIndexOf_FirstItems | 1,878,933,500.0000 ns | 17,118,131.6171 ns | 16,012,310.9355 ns | 1,870,009,600.0000 ns | 1,601.616 | 14.82 | - | - | - | 600 B | 0.000 | | List_IndexOf_LastItems | 57,303,575,140.0000 ns | 297,612,744.3548 ns | 278,387,145.7216 ns | 57,391,576,000.0000 ns | 48,792.865 | 303.56 | - | - | - | 600 B | 0.000 | | PooledList_IndexOf_LastItems | 57,032,399,106.6667 ns | 281,241,865.3817 ns | 263,073,815.3730 ns | 56,895,992,200.0000 ns | 48,566.622 | 322.88 | - | - | - | 600 B | 0.000 | -| RecyclableList_IndexOf_LastItems | 57,308,279,713.3333 ns | 272,718,905.6589 ns | 255,101,433.5602 ns | 57,297,645,400.0000 ns | 48,767.562 | 239.96 | - | - | - | 600 B | 0.000 | -| RecyclableList_LongIndexOf_LastItems | 57,198,323,460.0000 ns | 282,971,632.5816 ns | 264,691,840.6850 ns | 57,198,418,300.0000 ns | 48,669.107 | 304.11 | - | - | - | 600 B | 0.000 | +| RecyclableLongList_IndexOf_LastItems | 57,308,279,713.3333 ns | 272,718,905.6589 ns | 255,101,433.5602 ns | 57,297,645,400.0000 ns | 48,767.562 | 239.96 | - | - | - | 600 B | 0.000 | +| RecyclableLongList_LongIndexOf_LastItems | 57,198,323,460.0000 ns | 282,971,632.5816 ns | 264,691,840.6850 ns | 57,198,418,300.0000 ns | 48,669.107 | 304.11 | - | - | - | 600 B | 0.000 | | List_Remove_FirstItems | 5,023,030,012.5000 ns | 82,615,052.4052 ns | 107,422,903.9562 ns | 5,000,417,000.0000 ns | 4,295.171 | 116.37 | - | - | - | 4000656 B | 1.000 | | PooledList_Remove_FirstItems | 4,750,601,721.4286 ns | 17,989,258.8487 ns | 15,947,009.4038 ns | 4,747,622,550.0000 ns | 4,043.997 | 21.26 | - | - | - | 992 B | 0.000 | | RecyclableArrayList_Remove_FirstItems | 4,950,634,900.0000 ns | 33,761,094.2570 ns | 29,928,330.6849 ns | 4,936,519,050.0000 ns | 4,218.075 | 23.90 | - | - | - | 640 B | 0.000 | -| RecyclableList_Remove_FirstItems | 5,020,383,250.0000 ns | 100,209,734.5497 ns | 115,401,679.3276 ns | 5,029,163,750.0000 ns | 4,306.772 | 86.95 | - | - | - | 952 B | 0.000 | +| RecyclableLongList_Remove_FirstItems | 5,020,383,250.0000 ns | 100,209,734.5497 ns | 115,401,679.3276 ns | 5,029,163,750.0000 ns | 4,306.772 | 86.95 | - | - | - | 952 B | 0.000 | | List_Remove_LastItems | 56,593,869,333.3333 ns | 258,693,958.6041 ns | 241,982,489.3835 ns | 56,513,091,800.0000 ns | 48,189.227 | 272.02 | - | - | - | 4000656 B | 1.000 | | PooledList_Remove_LastItems | 56,465,443,542.8571 ns | 99,443,506.1766 ns | 88,154,078.0245 ns | 56,458,364,050.0000 ns | 48,092.866 | 216.09 | - | - | - | 992 B | 0.000 | | RecyclableArrayList_Remove_LastItems | 57,432,405,146.6667 ns | 264,062,625.8226 ns | 247,004,344.0307 ns | 57,409,508,000.0000 ns | 48,952.707 | 234.83 | - | - | - | 640 B | 0.000 | -| RecyclableList_Remove_LastItems | 57,077,678,728.5714 ns | 210,992,675.8689 ns | 187,039,511.4398 ns | 57,038,290,150.0000 ns | 48,614.503 | 242.79 | - | - | - | 952 B | 0.000 | +| RecyclableLongList_Remove_LastItems | 57,077,678,728.5714 ns | 210,992,675.8689 ns | 187,039,511.4398 ns | 57,038,290,150.0000 ns | 48,614.503 | 242.79 | - | - | - | 952 B | 0.000 | | List_RemoveAt_FirstItems | 4,517,669,893.3333 ns | 77,360,576.7460 ns | 72,363,131.4861 ns | 4,546,302,700.0000 ns | 3,850.590 | 62.34 | - | - | - | 4000656 B | 1.000 | | PooledList_RemoveAt_FirstItems | 4,439,417,700.0000 ns | 40,915,112.8948 ns | 38,272,021.9874 ns | 4,418,366,400.0000 ns | 3,779.751 | 38.92 | - | - | - | 992 B | 0.000 | | RecyclableArrayList_RemoveAt_FirstItems | 4,558,102,892.8571 ns | 25,076,973.8515 ns | 22,230,084.1404 ns | 4,559,174,800.0000 ns | 3,882.107 | 16.61 | - | - | - | 640 B | 0.000 | -| RecyclableList_RemoveAt_FirstItems | 4,617,033,766.6667 ns | 85,061,197.3076 ns | 79,566,296.7373 ns | 4,632,994,800.0000 ns | 3,928.768 | 72.17 | - | - | - | 952 B | 0.000 | +| RecyclableLongList_RemoveAt_FirstItems | 4,617,033,766.6667 ns | 85,061,197.3076 ns | 79,566,296.7373 ns | 4,632,994,800.0000 ns | 3,928.768 | 72.17 | - | - | - | 952 B | 0.000 | | List_RemoveAt_LastItems | 2,005,211.3281 ns | 40,078.0351 ns | 84,538.1787 ns | 2,010,579.1016 ns | 1.725 | 0.08 | 42.9688 | 42.9688 | 42.9688 | 4000306 B | 1.000 | | PooledList_RemoveAt_LastItems | 1,047,436.1654 ns | 5,655.2027 ns | 5,289.8801 ns | 1,044,690.9180 ns | 0.892 | 0.01 | - | - | - | 58 B | 0.000 | | RecyclableArrayList_RemoveAt_LastItems | 1,256,380.8969 ns | 9,142.3285 ns | 7,634.2584 ns | 1,254,354.9805 ns | 1.070 | 0.01 | - | - | - | 41 B | 0.000 | -| RecyclableList_RemoveAt_LastItems | 1,621,193.5826 ns | 20,030.6198 ns | 17,756.6227 ns | 1,620,789.8438 ns | 1.379 | 0.02 | - | - | - | 353 B | 0.000 | +| RecyclableLongList_RemoveAt_LastItems | 1,621,193.5826 ns | 20,030.6198 ns | 17,756.6227 ns | 1,620,789.8438 ns | 1.379 | 0.02 | - | - | - | 353 B | 0.000 | diff --git a/Recyclable.Collections/RecyclableArrayList.cs b/Recyclable.Collections/RecyclableArrayList.cs index 850a465..e1a841c 100644 --- a/Recyclable.Collections/RecyclableArrayList.cs +++ b/Recyclable.Collections/RecyclableArrayList.cs @@ -249,7 +249,7 @@ namespace Recyclable.Collections } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - public void AddRange(RecyclableList items) + public void AddRange(RecyclableLongList items) { if (items.LongCount == 0) { @@ -259,12 +259,12 @@ namespace Recyclable.Collections var sourceItemsCount = items.LongCount; if (sourceItemsCount > int.MaxValue) { - ThrowArgumentOutOfRangeException($"The number of items exceeds the maximum capacity of {nameof(RecyclableArrayList)}, equal {int.MaxValue}, equal {int.MaxValue}. Please consider using {nameof(RecyclableList)}, instead"); + ThrowArgumentOutOfRangeException($"The number of items exceeds the maximum capacity of {nameof(RecyclableArrayList)}, equal {int.MaxValue}, equal {int.MaxValue}. Please consider using {nameof(RecyclableLongList)}, instead"); } if (_count + sourceItemsCount > int.MaxValue) { - ThrowArgumentOutOfRangeException($"The total number of items in source and target table exceeds the maximum capacity of {nameof(RecyclableArrayList)}, equal {int.MaxValue}. Please consider using {nameof(RecyclableList)}, instead"); + ThrowArgumentOutOfRangeException($"The total number of items in source and target table exceeds the maximum capacity of {nameof(RecyclableArrayList)}, equal {int.MaxValue}. Please consider using {nameof(RecyclableLongList)}, instead"); } int targetCapacity = _count + (int)sourceItemsCount; diff --git a/Recyclable.Collections/RecyclableList.IndexOfHelpers.cs b/Recyclable.Collections/RecyclableLongList.IndexOfHelpers.cs similarity index 88% rename from Recyclable.Collections/RecyclableList.IndexOfHelpers.cs rename to Recyclable.Collections/RecyclableLongList.IndexOfHelpers.cs index 2026354..f702481 100644 --- a/Recyclable.Collections/RecyclableList.IndexOfHelpers.cs +++ b/Recyclable.Collections/RecyclableLongList.IndexOfHelpers.cs @@ -3,14 +3,14 @@ using Recyclable.Collections.Parallel; namespace Recyclable.Collections { - public partial class RecyclableList + public partial class RecyclableLongList { public static class IndexOfHelpers { [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] // [MethodImpl(MethodImplOptions.AggressiveInlining)] // [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.NoOptimization)] - private static void ScheduleIndexOfTask(IndexOfSynchronizationContext context, RecyclableList list, int blockIndex, T itemToFind) + private static void ScheduleIndexOfTask(IndexOfSynchronizationContext context, RecyclableLongList list, int blockIndex, T itemToFind) { _ = context.AllDoneSignal.AddParticipant(); // & WAS SLOWER @@ -123,7 +123,7 @@ namespace Recyclable.Collections [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] // [MethodImpl(MethodImplOptions.AggressiveInlining)] // [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.NoOptimization)] - private static void ScheduleIndexOfTaskSingle(IndexOfSynchronizationContext context, RecyclableList list, int blockIndex, T itemToFind) + private static void ScheduleIndexOfTaskSingle(IndexOfSynchronizationContext context, RecyclableLongList list, int blockIndex, T itemToFind) { _ = context.AllDoneSignal.AddParticipant(); // & WAS SLOWER @@ -162,7 +162,7 @@ namespace Recyclable.Collections private const int BlocksForEachTask = 4; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - public static long IndexOfParallel(RecyclableList list, in T item) + public static long IndexOfParallel(RecyclableLongList list, in T item) { // & WAS SLOWER //long itemsCount = Array.IndexOf(list._memoryBlocks[0], item, 0, (int)Math.Min(list._blockSize, list._longCount)); @@ -214,25 +214,43 @@ namespace Recyclable.Collections } } - int itemIndex = Array.IndexOf(list._memoryBlocks[list._lastBlockWithData], item, 0, list._nextItemIndex > 0 ? list._nextItemIndex : list._blockSize); - if (itemIndex >= 0) + if (!context._isItemFound) { - context._isItemFound = true; - _ = Interlocked.Exchange(ref context.FoundItemIndex, ((long)blockIndex << list._blockSizePow2BitShift) + itemIndex); + int itemIndex = Array.IndexOf(list._memoryBlocks[list._lastBlockWithData], item, 0, list._nextItemIndex > 0 ? list._nextItemIndex : list._blockSize); + if (!context._isItemFound && itemIndex >= 0) + { + context._isItemFound = true; + _ = Interlocked.Exchange(ref context.FoundItemIndex, ((long)blockIndex << list._blockSizePow2BitShift) + itemIndex); + } } context.AllDoneSignal.SignalAndWait(); if (context.Exception == null) { - return context.FoundItemIndex; + try + { + return context.FoundItemIndex; + } + finally + { + context.Dispose(); + } } - context.Exception.CaptureAndRethrow(); + try + { + context.Exception.CaptureAndRethrow(); + } + finally + { + context.Dispose(); + } + return RecyclableDefaults.ItemNotFoundIndexLong; } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - public static long IndexOfSequential(RecyclableList list, in T item) //, in T[][] memoryBlocks, int lastBlockIndex, int blockSize, int nextItemIndex) + public static long IndexOfSequential(RecyclableLongList list, in T item) //, in T[][] memoryBlocks, int lastBlockIndex, int blockSize, int nextItemIndex) { int itemIndex; // & WAS SLOWER diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableLongList.cs similarity index 95% rename from Recyclable.Collections/RecyclableList.cs rename to Recyclable.Collections/RecyclableLongList.cs index c397ea1..4d914e9 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableLongList.cs @@ -8,7 +8,7 @@ using Recyclable.Collections.Pools; namespace Recyclable.Collections { - public partial class RecyclableList : IDisposable, IList + public partial class RecyclableLongList : IDisposable, IList { private static readonly ArrayPool _defaultMemoryBlocksPool = ArrayPool.Create(); private static readonly ArrayPool _defaultBlockArrayPool = ArrayPool.Create(); @@ -55,7 +55,7 @@ namespace Recyclable.Collections public int NextItemIndex => _nextItemIndex; [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - private static void CopyItems(RecyclableList list, long index) + private static void CopyItems(RecyclableLongList list, long index) { T[][] memoryBlocks = list._memoryBlocks; int nextItemIndex = list._nextItemIndex; @@ -219,10 +219,10 @@ namespace Recyclable.Collections /// /// Creates a set of new memory buffers, if needed, to allow storing at minimum no. of items. /// - /// that needs to be resized. + /// that needs to be resized. /// Minimal requested block size. It MUST be rounded to the power of 2, see remarks. /// Pre-calculated bit shifting value for left & right shift operations against. - /// The minimum no. of items MUST be able to store after . + /// The minimum no. of items MUST be able to store after . /// /// For performance reasons, MUST a power of 2. This simplifies a lot block & item /// index calculations, i.e. makes them logical operations on bits. @@ -235,7 +235,7 @@ namespace Recyclable.Collections /// /// The maximum no. of items can store. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static long Resize(RecyclableList list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) + protected static long Resize(RecyclableLongList list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity) { ArrayPool blockArrayPool = list._blockArrayPool; int sourceBlockCount = list._reservedBlockCount; @@ -329,7 +329,7 @@ namespace Recyclable.Collections // [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.NoOptimization)] // & WAS SLOWER // [MethodImpl(MethodImplOptions.NoInlining)] - //private static void Iterate(RecyclableList list, in ParallelSynchronizationContext context, in T itemToFind) + //private static void Iterate(RecyclableLongList list, in ParallelSynchronizationContext context, in T itemToFind) //{ // // TODO: Switch to use _blockSize instead of list._longCountIndeexOfStep for simplifications & better performance. @@ -357,7 +357,7 @@ namespace Recyclable.Collections //} [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static void SetupBlockArrayPooling(RecyclableList list, int blockSize, ArrayPool? blockArrayPool = null) + protected static void SetupBlockArrayPooling(RecyclableLongList list, int blockSize, ArrayPool? blockArrayPool = null) { list._blockSize = blockSize; list._blockSizePow2BitShift = (byte)(31 - BitOperations.LeadingZeroCount((uint)blockSize)); @@ -367,7 +367,7 @@ namespace Recyclable.Collections } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - protected static long EnsureCapacity(RecyclableList list, long requestedCapacity) + protected static long EnsureCapacity(RecyclableLongList list, long requestedCapacity) { long newCapacity = list._capacity > 0 ? checked((long)BitOperations.RoundUpToPowerOf2((ulong)requestedCapacity)) @@ -387,7 +387,7 @@ namespace Recyclable.Collections [MethodImpl(MethodImplOptions.AggressiveOptimization)] #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableList(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongList(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -416,7 +416,7 @@ namespace Recyclable.Collections } #pragma warning disable CS8618 // It's set by SetupBlockArrayPooling - public RecyclableList(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) + public RecyclableLongList(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool? memoryBlocksPool = default, ArrayPool? blockArrayPool = default) #pragma warning restore CS8618 { _memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool; @@ -565,7 +565,7 @@ namespace Recyclable.Collections _lastBlockWithData = targetBlockIndex - (itemsSpan.Length > 0 ? 0 : 1); } - public void AddRange(RecyclableList items) + public void AddRange(RecyclableLongList items) { if (items.LongCount == 0) { @@ -741,9 +741,9 @@ namespace Recyclable.Collections public void AddRange(IEnumerable source, int growByCount = RecyclableDefaults.BlockSize) { - if (source is RecyclableList sourceRecyclableList) + if (source is RecyclableLongList sourceRecyclableLongList) { - AddRange(sourceRecyclableList); + AddRange(sourceRecyclableLongList); return; } @@ -1055,7 +1055,7 @@ namespace Recyclable.Collections IEnumerator IEnumerable.GetEnumerator() => _memoryBlocks.Enumerate(_blockSize, LongCount).GetEnumerator(); - ~RecyclableList() + ~RecyclableLongList() { // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method Dispose(); diff --git a/Recyclable.Collections/RecyclableListExtensions.cs b/Recyclable.Collections/RecyclableLongListExtensions.cs similarity index 88% rename from Recyclable.Collections/RecyclableListExtensions.cs rename to Recyclable.Collections/RecyclableLongListExtensions.cs index fedf113..b4073e4 100644 --- a/Recyclable.Collections/RecyclableListExtensions.cs +++ b/Recyclable.Collections/RecyclableLongListExtensions.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; namespace Recyclable.Collections { - public static class RecyclableListExtensions + public static class RecyclableLongListExtensions { private const int _minPooledArraySize = RecyclableDefaults.MinPooledArrayLength; private const long ItemNotFoundIndexLong = -1L; @@ -46,7 +46,7 @@ namespace Recyclable.Collections } //[MethodImpl(MethodImplOptions.AggressiveInlining)] - //public static bool Contains(this RecyclableList arrays, T item) => arrays.Any(x => x.Contains(item)); + //public static bool Contains(this RecyclableLongList arrays, T item) => arrays.Any(x => x.Contains(item)); public static IEnumerable Enumerate(this T[][] arrays, int chunkSize, long totalCount) { @@ -83,7 +83,7 @@ namespace Recyclable.Collections // => comparer.Compare(value, maxValue) > 0 ? maxValue : value; //[MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long LongIndexOf(this RecyclableList arrays, long itemsCount, T itemToFind, IEqualityComparer comparer) + public static long LongIndexOf(this RecyclableLongList arrays, long itemsCount, T itemToFind, IEqualityComparer comparer) { for (var itemIdx = 0L; itemIdx < itemsCount; itemIdx++) { @@ -126,10 +126,10 @@ namespace Recyclable.Collections } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RecyclableList ToRecyclableList(this IList values, int blockSize = RecyclableDefaults.BlockSize) => new(values, blockSize); + public static RecyclableLongList ToRecyclableLongList(this IList values, int blockSize = RecyclableDefaults.BlockSize) => new(values, blockSize); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RecyclableList ToRecyclableList(this List values, int blockSize = RecyclableDefaults.BlockSize) => new(values, blockSize); + public static RecyclableLongList ToRecyclableLongList(this List values, int blockSize = RecyclableDefaults.BlockSize) => new(values, blockSize); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RecyclableArrayList ToRecyclableArrayList(this IEnumerable values) => new(values); @@ -144,7 +144,7 @@ namespace Recyclable.Collections public static RecyclableArrayList ToRecyclableArrayList(this RecyclableArrayList values) => new(values); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RecyclableList ToRecyclableList(this IEnumerable values, int minBlockSize = RecyclableDefaults.BlockSize) => new(values, minBlockSize: minBlockSize); + public static RecyclableLongList ToRecyclableLongList(this IEnumerable values, int minBlockSize = RecyclableDefaults.BlockSize) => new(values, minBlockSize: minBlockSize); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] RentArrayFromPool(this int minSize, ArrayPool arrayPool) => (minSize >= _minPooledArraySize) diff --git a/Recyclable.Collections/RecyclableSortedList.cs b/Recyclable.Collections/RecyclableSortedList.cs index c3e63bd..b947e9d 100644 --- a/Recyclable.Collections/RecyclableSortedList.cs +++ b/Recyclable.Collections/RecyclableSortedList.cs @@ -1,6 +1,6 @@ namespace Recyclable.Collections { - public class RecyclableSortedList : RecyclableList<(TKey Key, TValue Value)> + public class RecyclableSortedList : RecyclableLongList<(TKey Key, TValue Value)> where TKey : notnull { private static readonly IComparer<(TKey, TValue)> _comparer = new FrequencyTupleComparer(); diff --git a/Recyclable.Collections/RecyclableStack.cs b/Recyclable.Collections/RecyclableStack.cs index fb67715..50d7140 100644 --- a/Recyclable.Collections/RecyclableStack.cs +++ b/Recyclable.Collections/RecyclableStack.cs @@ -7,7 +7,7 @@ namespace Recyclable.Collections private bool _disposedValue; private readonly int _blockSize; - protected RecyclableList List { get; } + protected RecyclableLongList List { get; } public int Count => List.Count; public long LongCount { @@ -32,7 +32,7 @@ namespace Recyclable.Collections List = new(list, blockSize); } - public RecyclableStack(RecyclableList list, int blockSize = RecyclableDefaults.BlockSize) + public RecyclableStack(RecyclableLongList list, int blockSize = RecyclableDefaults.BlockSize) { _blockSize = blockSize; List = new(list, blockSize); diff --git a/Recyclable.Collections/SearchConfiguration.cs b/Recyclable.Collections/SearchConfiguration.cs index 622ae2a..0150a28 100644 --- a/Recyclable.Collections/SearchConfiguration.cs +++ b/Recyclable.Collections/SearchConfiguration.cs @@ -16,7 +16,7 @@ namespace Recyclable.Collections // List = list; // } - public static SearchConfiguration, TItem> CreateFrom(RecyclableList list, in TItem itemToFind) => new() + public static SearchConfiguration, TItem> CreateFrom(RecyclableLongList list, in TItem itemToFind) => new() { List = list, ItemToFind = itemToFind, diff --git a/Recyclable.CollectionsTests/RecyclableArrayListTests.cs b/Recyclable.CollectionsTests/RecyclableArrayListTests.cs index 66d6c01..192f624 100644 --- a/Recyclable.CollectionsTests/RecyclableArrayListTests.cs +++ b/Recyclable.CollectionsTests/RecyclableArrayListTests.cs @@ -6,7 +6,7 @@ namespace Recyclable.CollectionsTests public class RecyclableArrayListTests { [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddRangeShouldAddItemsInCorrectOrder(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -25,9 +25,9 @@ namespace Recyclable.CollectionsTests { list.AddRange(testDataRecyclableArrayList); } - else if (testData is RecyclableList testDataRecyclableList) + else if (testData is RecyclableLongList testDataRecyclableLongList) { - list.AddRange(testDataRecyclableList); + list.AddRange(testDataRecyclableLongList); } else if (testData is IList testDataIList) { @@ -49,7 +49,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.EmptySourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.EmptySourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddRangeShouldDoNothingWhenSourceIsEmpty(string testCase, IEnumerable testData) { // Prepare @@ -68,9 +68,9 @@ namespace Recyclable.CollectionsTests { list.AddRange(testDataRecyclableArrayList); } - else if (testData is RecyclableList testDataRecyclableList) + else if (testData is RecyclableLongList testDataRecyclableLongList) { - list.AddRange(testDataRecyclableList); + list.AddRange(testDataRecyclableLongList); } else if (testData is IList testDataIList) { @@ -92,7 +92,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddRangeShouldNotOverrideItems(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -114,10 +114,10 @@ namespace Recyclable.CollectionsTests list.AddRange(testDataRecyclableArrayList); list.AddRange(testDataRecyclableArrayList); } - else if (testData is RecyclableList testDataRecyclableList) + else if (testData is RecyclableLongList testDataRecyclableLongList) { - list.AddRange(testDataRecyclableList); - list.AddRange(testDataRecyclableList); + list.AddRange(testDataRecyclableLongList); + list.AddRange(testDataRecyclableLongList); } else if (testData is IList testDataIList) { @@ -147,7 +147,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddShouldAcceptDuplicates(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -166,7 +166,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddShouldAddItems(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -186,7 +186,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddShouldAddItemWhenAfterAddRange(string testCase, IEnumerable testData, long itemsCount) { // Act @@ -203,7 +203,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ClearShouldRemoveAllItems(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -220,7 +220,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConsecutiveDisposeShouldSucceed(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -232,7 +232,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConstructorShouldAcceptDuplicates(string testCase, IEnumerable testData, long itemsCount) { // Act @@ -244,7 +244,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConstructorShouldAddItemsInCorrectOrderWhenSourceIsIEnumerable(string testCase, IEnumerable testData, long itemsCount) { // Act @@ -257,7 +257,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConstructorSourceShouldInitializeList(string testCase, IEnumerable testData, long itemsCount) { // Act @@ -269,7 +269,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ContainsShouldFindAllItems(string testCase, IEnumerable testData, long itemsCount) { if (itemsCount == 0) @@ -301,7 +301,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ContainsShouldNotFindNonExistingItems(string testCase, IEnumerable testData, long itemsCount) { if (itemsCount == 0) @@ -325,7 +325,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void CopyToShouldCopyAllItemsInTheCorrectOrder(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -341,7 +341,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void EnumerateShouldYieldAllItemsInCorrectOrder(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -368,7 +368,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void IndexOfShouldNotFindNonExistingItems(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -394,7 +394,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void IndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -409,7 +409,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void InitializeSortClearAddRangeRemoveShouldSucceed(string testCase, IEnumerable testData, long itemsCount) { if (itemsCount == 0) @@ -447,7 +447,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void InsertAtTheBeginningShouldMoveItems(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -467,7 +467,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveAtFromTheBeginningShouldSucceed(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -489,7 +489,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveAtFromTheEndShouldSucceed(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -511,7 +511,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveFromTheBeginningShouldRemoveTheCorrectItem(string testCase, IEnumerable testData, long itemsCount) { // Prepare @@ -530,7 +530,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveFromTheEndShouldRemoveTheCorrectItem(string testCase, IEnumerable testData, long itemsCount) { // Act & Validate diff --git a/Recyclable.CollectionsTests/RecyclableListTestData.cs b/Recyclable.CollectionsTests/RecyclableLongListTestData.cs similarity index 91% rename from Recyclable.CollectionsTests/RecyclableListTestData.cs rename to Recyclable.CollectionsTests/RecyclableLongListTestData.cs index 6163458..ac7111b 100644 --- a/Recyclable.CollectionsTests/RecyclableListTestData.cs +++ b/Recyclable.CollectionsTests/RecyclableLongListTestData.cs @@ -2,7 +2,7 @@ namespace Recyclable.CollectionsTests { - public static class RecyclableListTestData + public static class RecyclableLongListTestData { private static IEnumerable DoCreateTestData(long itemsCount) { @@ -50,8 +50,8 @@ namespace Recyclable.CollectionsTests { yield return new object[] { - $"RecyclableList(itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize})", - CreateTestData(itemsCount).ToRecyclableList(sourceBlockSize), + $"RecyclableLongList(itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize})", + CreateTestData(itemsCount).ToRecyclableLongList(sourceBlockSize), itemsCount }; } @@ -69,7 +69,7 @@ namespace Recyclable.CollectionsTests new object[] { "int[]", Array.Empty() }, new object[] { "List", Array.Empty().ToList() }, new object[] { "RecyclableArrayList", Array.Empty().ToRecyclableArrayList() }, - new object[] { "RecyclableList", Array.Empty().ToRecyclableList() }, + new object[] { "RecyclableLongList", Array.Empty().ToRecyclableLongList() }, new object[] { "IList", new CustomIList(Array.Empty()) }, new object[] { "IEnumerable with non-enumerated count", Array.Empty().AsEnumerable() }, new object[] { "IEnumerable without non-enumerated count", new EnumerableWithoutCount(Array.Empty()) } diff --git a/Recyclable.CollectionsTests/RecyclableListTests.cs b/Recyclable.CollectionsTests/RecyclableLongListTests.cs similarity index 69% rename from Recyclable.CollectionsTests/RecyclableListTests.cs rename to Recyclable.CollectionsTests/RecyclableLongListTests.cs index af4a0aa..4f8669c 100644 --- a/Recyclable.CollectionsTests/RecyclableListTests.cs +++ b/Recyclable.CollectionsTests/RecyclableLongListTests.cs @@ -3,14 +3,14 @@ using Recyclable.Collections; namespace Recyclable.CollectionsTests { - public class RecyclableListTests + public class RecyclableLongListTests { [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddRangeShouldAddItemsInCorrectOrder(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(minBlockSize: targetBlockSize); // Act if (testData is long[] testDataArray) @@ -25,7 +25,7 @@ namespace Recyclable.CollectionsTests { list.AddRange(testDataRecyclableArrayList); } - else if (testData is RecyclableList testDataRecyclableList) + else if (testData is RecyclableLongList testDataRecyclableList) { list.AddRange(testDataRecyclableList); } @@ -50,11 +50,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.EmptySourceDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.EmptySourceDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddRangeShouldDoNothingWhenSourceIsEmpty(string testCase, IEnumerable testData) { // Prepare - using var list = new RecyclableList(); + using var list = new RecyclableLongList(); // Act if (testData is long[] testDataArray) @@ -69,7 +69,7 @@ namespace Recyclable.CollectionsTests { list.AddRange(testDataRecyclableArrayList); } - else if (testData is RecyclableList testDataRecyclableList) + else if (testData is RecyclableLongList testDataRecyclableList) { list.AddRange(testDataRecyclableList); } @@ -93,11 +93,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddRangeShouldNotOverrideItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(minBlockSize: targetBlockSize); // Act if (testData is long[] testDataArray) @@ -115,7 +115,7 @@ namespace Recyclable.CollectionsTests list.AddRange(testDataRecyclableArrayList); list.AddRange(testDataRecyclableArrayList); } - else if (testData is RecyclableList testDataRecyclableList) + else if (testData is RecyclableLongList testDataRecyclableList) { list.AddRange(testDataRecyclableList); list.AddRange(testDataRecyclableList); @@ -148,14 +148,14 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddShouldAcceptDuplicates(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare testData = testData.Concat(testData).ToArray(); // Act - using var list = new RecyclableList(minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(minBlockSize: targetBlockSize); foreach (var index in testData) { list.Add(index); @@ -167,11 +167,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void AddShouldAddItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(minBlockSize: targetBlockSize); // Act foreach (var index in testData) @@ -185,11 +185,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void GetByIndexShouldReturnCorrectItem(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act & Validate foreach (var item in testData) @@ -199,12 +199,12 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] //[InlineData("Debugging case", new long[1] { 1 }, 1, 2)] public void AddShouldAddItemWhenAfterAddRange(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Act - using var list = new RecyclableList(minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(minBlockSize: targetBlockSize); list.AddRange(testData); foreach (var index in testData) { @@ -217,11 +217,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ClearShouldRemoveAllItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize, expectedItemsCount: itemsCount); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize, expectedItemsCount: itemsCount); _ = list.LongCount.Should().Be(itemsCount); // Act @@ -234,11 +234,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConsecutiveDisposeShouldSucceed(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); list.Dispose(); // Act @@ -246,14 +246,14 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConstructorShouldAcceptDuplicates(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare testData = testData.Concat(testData).ToArray(); // Act - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Validate _ = list.LongCount.Should().Be(itemsCount * 2); @@ -261,11 +261,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConstructorShouldAddItemsInCorrectOrderWhenSourceIsIEnumerable(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Act - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Validate _ = list.Capacity.Should().BeGreaterThanOrEqualTo((int)itemsCount, "when we succeed in taking count without enumerating, then we allocate as much memory as needed, only"); @@ -274,11 +274,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ConstructorSourceShouldInitializeList(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Act - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Validate _ = list.LongCount.Should().Be(itemsCount); @@ -286,7 +286,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ContainsShouldFindAllItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare @@ -296,7 +296,7 @@ namespace Recyclable.CollectionsTests return; } - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); _ = testData.Any().Should().BeTrue("we need items on the list that we can look for"); // Act @@ -308,11 +308,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.TargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.TargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ContainsShouldNotFindAnythingWhenListEmpty(long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(minBlockSize: targetBlockSize, expectedItemsCount: itemsCount); + using var list = new RecyclableLongList(minBlockSize: targetBlockSize, expectedItemsCount: itemsCount); // Validate _ = list.Contains(0).Should().BeFalse(); @@ -320,7 +320,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void ContainsShouldNotFindNonExistingItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare @@ -330,7 +330,7 @@ namespace Recyclable.CollectionsTests return; } - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); _ = testData.Any().Should().BeTrue("we need items on the list that we can look for"); // Act @@ -345,12 +345,12 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] //[InlineData("Debuging case", new[] { 1L, 2, }, 2, 2)] public void CopyToShouldCopyAllItemsInTheCorrectOrder(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act var actual = new long[itemsCount]; @@ -359,11 +359,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void DisposeShouldSucceed(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act list.Dispose(); @@ -374,11 +374,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void EnumerateShouldYieldAllItemsInCorrectOrder(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act var actual = new List(); @@ -396,7 +396,7 @@ namespace Recyclable.CollectionsTests public void IndexOfShouldNotFindAnythingWhenListEmpty() { // Prepare - using var list = new RecyclableList(); + using var list = new RecyclableLongList(); // Validate _ = list.IndexOf(0).Should().Be(-1); @@ -404,7 +404,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void IndexOfShouldNotFindNonExistingItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare @@ -415,7 +415,7 @@ namespace Recyclable.CollectionsTests } // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); _ = testData.Any().Should().BeTrue("we need items on the list that we can look for"); // Act @@ -430,11 +430,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void IndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act & Validate foreach (var item in testData) @@ -445,7 +445,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void InitializeSortClearAddRangeRemoveShouldSucceed(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { if (itemsCount == 0) @@ -454,7 +454,7 @@ namespace Recyclable.CollectionsTests } // Act - using RecyclableList list = new(testData, minBlockSize: targetBlockSize); + using RecyclableLongList list = new(testData, minBlockSize: targetBlockSize); list.QuickSort(); // Validate @@ -483,22 +483,22 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void InsertAtTheBeginningShouldMoveItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act _ = Assert.Throws(() => list.Insert(0, -1)); } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void InsertShouldRaiseNotSupportedException(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act _ = Assert.Throws(() => list.Insert(0, -1)); @@ -508,7 +508,7 @@ namespace Recyclable.CollectionsTests public void LongIndexOfShouldNotFindAnythingWhenListEmpty() { // Prepare - using var list = new RecyclableList(); + using var list = new RecyclableLongList(); // Validate _ = list.LongIndexOf(0).Should().Be(-1); @@ -516,7 +516,7 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void LongIndexOfShouldNotFindNonExistingItems(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { if (itemsCount == 0) @@ -525,7 +525,7 @@ namespace Recyclable.CollectionsTests } // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); _ = testData.Any().Should().BeTrue("we need items on the list that we can look for"); // Act @@ -540,11 +540,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void LongIndexOfShouldReturnCorrectIndexes(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act & Validate foreach (var item in testData) @@ -558,11 +558,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveAtFromTheBeginningShouldSucceed(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act & Validate for (var deleted = 1; deleted <= itemsCount; deleted++) @@ -580,11 +580,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveAtFromTheEndShouldSucceed(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act & Validate for (var deleted = 1; deleted <= itemsCount; deleted++) @@ -602,11 +602,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveFromTheBeginningShouldRemoveTheCorrectItem(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); // Act & Validate for (var deleted = 1; deleted <= itemsCount; deleted++) @@ -621,11 +621,11 @@ namespace Recyclable.CollectionsTests } [Theory] - [MemberData(nameof(RecyclableListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableListTestData))] + [MemberData(nameof(RecyclableLongListTestData.SourceTargetDataVariants), MemberType = typeof(RecyclableLongListTestData))] public void RemoveFromTheEndShouldRemoveTheCorrectItem(string testCase, IEnumerable testData, long itemsCount, int targetBlockSize) { // Prepare - using var list = new RecyclableList(testData, minBlockSize: targetBlockSize); + using var list = new RecyclableLongList(testData, minBlockSize: targetBlockSize); var expectedData = testData.ToArray(); int removedCount = 0; foreach (var item in testData.Reverse()) diff --git a/Recyclable.CollectionsTests/RecyclableQueueTests.cs b/Recyclable.CollectionsTests/RecyclableQueueTests.cs index 4940eb9..fbbeea0 100644 --- a/Recyclable.CollectionsTests/RecyclableQueueTests.cs +++ b/Recyclable.CollectionsTests/RecyclableQueueTests.cs @@ -72,7 +72,7 @@ namespace Recyclable.CollectionsTests list.Enqueue(_testData[itemIdx]); } - var dequeuedItems = new RecyclableList(); + var dequeuedItems = new RecyclableLongList(); while (list.LongCount > 0) { dequeuedItems.Add(list.Dequeue()); @@ -106,7 +106,7 @@ namespace Recyclable.CollectionsTests using var list = new RecyclableQueue(_testData); // Act - var actual = new RecyclableList(); + var actual = new RecyclableLongList(); using var enumerator = list.GetEnumerator(); while (enumerator.MoveNext()) { diff --git a/Recyclable.CollectionsTests/RecyclableStackTests.cs b/Recyclable.CollectionsTests/RecyclableStackTests.cs index e6330a0..dffdd52 100644 --- a/Recyclable.CollectionsTests/RecyclableStackTests.cs +++ b/Recyclable.CollectionsTests/RecyclableStackTests.cs @@ -14,7 +14,7 @@ namespace Recyclable.CollectionsTests using var list = new RecyclableStack(_testData); // Act - var actual = new RecyclableList(); + var actual = new RecyclableLongList(); using var enumerator = list.GetEnumerator(); while (enumerator.MoveNext()) { @@ -90,7 +90,7 @@ namespace Recyclable.CollectionsTests list.Push(_testData[itemIdx]); } - var dequeuedItems = new RecyclableList(); + var dequeuedItems = new RecyclableLongList(); while (list.LongCount > 0) { dequeuedItems.Add(list.Pop());