| Enumerable_ToList | main | 1 | 25.87 ns | 1.00 | 112 B | 1.00 |
| Enumerable_ToList | pr | 1 | 28.49 ns | 1.10 | 104 B | 0.93 |
| | | | | | |
| IEnumerableSelectIterator_ToList | main | 1 | 46.05 ns | 1.00 | 168 B | 1.00 |
| IEnumerableSelectIterator_ToList | pr | 1 | 48.76 ns | 1.06 | 160 B | 0.95 |
| | | | | | |
| IteratorSelectIterator_ToList | main | 1 | 55.84 ns | 1.00 | 184 B | 1.00 |
| IteratorSelectIterator_ToList | pr | 1 | 60.04 ns | 1.08 | 184 B | 1.00 |
| | | | | | |
| OfTypeIterator_ToList | main | 1 | 61.88 ns | 1.00 | 200 B | 1.00 |
| OfTypeIterator_ToList | pr | 1 | 65.08 ns | 1.05 | 176 B | 0.88 |
| | | | | | |
| SelectManySingleSelectorIterator_ToList | main | 1 | 62.16 ns | 1.00 | 240 B | 1.00 |
| SelectManySingleSelectorIterator_ToList | pr | 1 | 67.54 ns | 1.08 | 232 B | 0.97 |
| | | | | | |
| IEnumerableSkipTakeIterator_ToLost | main | 1 | 41.68 ns | 1.00 | 128 B | 1.00 |
| IEnumerableSkipTakeIterator_ToLost | pr | 1 | 43.83 ns | 1.05 | 128 B | 1.00 |
| | | | | | |
| IEnumerableWhereIterator_ToList | main | 1 | 42.11 ns | 1.00 | 168 B | 1.00 |
| IEnumerableWhereIterator_ToList | pr | 1 | 42.63 ns | 1.01 | 160 B | 0.95 |
| | | | | | |
| ArrayWhereIterator_ToList | main | 1 | 38.62 ns | 1.00 | 152 B | 1.00 |
| ArrayWhereIterator_ToList | pr | 1 | 45.68 ns | 1.18 | 144 B | 0.95 |
| | | | | | |
| IEnumerableWhereSelectIterator_ToList | main | 1 | 60.61 ns | 1.00 | 232 B | 1.00 |
| IEnumerableWhereSelectIterator_ToList | pr | 1 | 65.19 ns | 1.10 | 224 B | 0.97 |
| | | | | | |
| ArrayWhereSelectIterator_ToList | main | 1 | 55.79 ns | 1.00 | 208 B | 1.00 |
| ArrayWhereSelectIterator_ToList | pr | 1 | 60.01 ns | 1.07 | 200 B | 0.96 |
| | | | | | |
| Enumerable_ToList | main | 5 | 44.33 ns | 1.00 | 168 B | 1.00 |
| Enumerable_ToList | pr | 5 | 32.99 ns | 0.74 | 120 B | 0.71 |
| | | | | | |
| IEnumerableSelectIterator_ToList | main | 5 | 65.96 ns | 1.00 | 224 B | 1.00 |
| IEnumerableSelectIterator_ToList | pr | 5 | 56.28 ns | 0.85 | 176 B | 0.79 |
| | | | | | |
| IteratorSelectIterator_ToList | main | 5 | 73.91 ns | 1.00 | 224 B | 1.00 |
| IteratorSelectIterator_ToList | pr | 5 | 77.94 ns | 1.05 | 224 B | 1.00 |
| | | | | | |
| OfTypeIterator_ToList | main | 5 | 132.67 ns | 1.00 | 384 B | 1.00 |
| OfTypeIterator_ToList | pr | 5 | 115.63 ns | 0.87 | 304 B | 0.79 |
| | | | | | |
| SelectManySingleSelectorIterator_ToList | main | 5 | 122.24 ns | 1.00 | 296 B | 1.00 |
| SelectManySingleSelectorIterator_ToList | pr | 5 | 106.91 ns | 0.88 | 248 B | 0.84 |
| | | | | | |
| IEnumerableSkipTakeIterator_ToLost | main | 5 | 56.19 ns | 1.00 | 168 B | 1.00 |
| IEnumerableSkipTakeIterator_ToLost | pr | 5 | 58.61 ns | 1.04 | 168 B | 1.00 |
| | | | | | |
| IEnumerableWhereIterator_ToList | main | 5 | 62.12 ns | 1.00 | 224 B | 1.00 |
| IEnumerableWhereIterator_ToList | pr | 5 | 50.66 ns | 0.81 | 176 B | 0.79 |
| | | | | | |
| ArrayWhereIterator_ToList | main | 5 | 56.66 ns | 1.00 | 224 B | 1.00 |
| ArrayWhereIterator_ToList | pr | 5 | 49.61 ns | 0.88 | 176 B | 0.79 |
| | | | | | |
| IEnumerableWhereSelectIterator_ToList | main | 5 | 82.31 ns | 1.00 | 288 B | 1.00 |
| IEnumerableWhereSelectIterator_ToList | pr | 5 | 72.20 ns | 0.88 | 240 B | 0.83 |
| | | | | | |
| ArrayWhereSelectIterator_ToList | main | 5 | 74.32 ns | 1.00 | 280 B | 1.00 |
| ArrayWhereSelectIterator_ToList | pr | 5 | 62.94 ns | 0.85 | 232 B | 0.83 |
| | | | | | |
| Enumerable_ToList | main | 50 | 167.20 ns | 1.00 | 688 B | 1.00 |
| Enumerable_ToList | pr | 50 | 118.14 ns | 0.71 | 296 B | 0.43 |
| | | | | | |
| IEnumerableSelectIterator_ToList | main | 50 | 191.60 ns | 1.00 | 744 B | 1.00 |
| IEnumerableSelectIterator_ToList | pr | 50 | 171.93 ns | 0.90 | 352 B | 0.47 |
| | | | | | |
| IteratorSelectIterator_ToList | main | 50 | 251.54 ns | 1.00 | 800 B | 1.00 |
| IteratorSelectIterator_ToList | pr | 50 | 231.18 ns | 0.92 | 408 B | 0.51 |
| | | | | | |
| OfTypeIterator_ToList | main | 50 | 731.40 ns | 1.00 | 2432 B | 1.00 |
| OfTypeIterator_ToList | pr | 50 | 734.97 ns | 1.01 | 1744 B | 0.72 |
| | | | | | |
| SelectManySingleSelectorIterator_ToList | main | 50 | 692.19 ns | 1.00 | 816 B | 1.00 |
| SelectManySingleSelectorIterator_ToList | pr | 50 | 656.03 ns | 0.95 | 424 B | 0.52 |
| | | | | | |
| IEnumerableSkipTakeIterator_ToLost | main | 50 | 186.72 ns | 1.00 | 744 B | 1.00 |
| IEnumerableSkipTakeIterator_ToLost | pr | 50 | 161.33 ns | 0.86 | 352 B | 0.47 |
| | | | | | |
| IEnumerableWhereIterator_ToList | main | 50 | 187.08 ns | 1.00 | 744 B | 1.00 |
| IEnumerableWhereIterator_ToList | pr | 50 | 164.58 ns | 0.88 | 352 B | 0.47 |
| | | | | | |
| ArrayWhereIterator_ToList | main | 50 | 154.86 ns | 1.00 | 920 B | 1.00 |
| ArrayWhereIterator_ToList | pr | 50 | 141.83 ns | 0.92 | 528 B | 0.57 |
| | | | | | |
| IEnumerableWhereSelectIterator_ToList | main | 50 | 209.25 ns | 1.00 | 808 B | 1.00 |
| IEnumerableWhereSelectIterator_ToList | pr | 50 | 186.49 ns | 0.89 | 416 B | 0.51 |
| | | | | | |
| ArrayWhereSelectIterator_ToList | main | 50 | 171.83 ns | 1.00 | 976 B | 1.00 |
| ArrayWhereSelectIterator_ToList | pr | 50 | 145.71 ns | 0.85 | 584 B | 0.60 |
Uh oh!
There was an error while loading.Please reload this page.
After#96570,
ToArray()in many places is faster and has fewer allocations thatToList(). As aListis just a wrapper over an array, we can re-use most of the logic inSegmentedArrayBuilderto buildLists, too.There were some more complex cases using
SegmentedArrayBuilderfor exampleConcatwhere I left the code as-is. I can also experiment with performance numbers for those if it is requested.Benchmarks
Enumerable_ToList changes have been reverted, they are not in current PR version
Int32Tests
ObjectTests
Benchmark Code
Command Line
Program.cs
Performance Analysis
In all cases allocations are down and sometimes significantly so. As the size of the collection increases so do the savings due to reduced number of "unnecessary" array copies as the list grows.
Speed is more of a trade-off. For lower counts the PR is actually slower whereas for higher counts it is faster, again due to less time copying data around.
However this must be seen in context; we are trading off nanoseconds. In situations where nanoseconds of individual LINQ operations matter, it would probably be recommended to write the loops by hand anyway. On this basis I would say that creating less garbage to collect would probably be better for the overall system performance than the slower code for the Count less than 5 case.