Recently, I was looking for a fast list and stumbled upon Loyc's
AList<T> is part of a bunch of generic collection classes, that have been introduced here at Code Project already by Qwertie. In this tip, you'll find a simple comparison of performance, which I have missed in the original article.
The generic collection classes of the .NET standard library do a very good job, especially:
- for small and medium size collections and
- primarily for element read access and append operations
Conversely, they tend to be less suitable:
- for large lists and
- insert-at or remove-at (random access) operations
Let's take a look at the performance...
Using the Code
I have prepared three solutions (.NET Framework 4.6, .NET Core 2.1 and Mono/.NET 4.5) with exactly the same test case - random access insert-at and delete-at operations. This is the only scenario, that is worth inspecting - in all other cases, the .NET standard library is the best choice.
AList<T> is available as NuGet package, compiled for 'Any CPU' targeting .NET 4.5, and source code at GitHub, that supports multiple targets: ,NET 3.5, .NET 4.0 and .NET 4.5.
It is easy to integrate the NuGet packages into the .NET Framework 4.6.1 and the Mono/.NET 4.5 projects. To get Loyc's
AList<T> running for .NET Core 2.1, I had to adopt the source code - but this was done in less than 10 minutes as well.
The performance comparison (linear scale - to get an impression of the difference between best and worst):
The performance comparison (logarithmic scale - to display even the small figures):
The raw figures:
How it looks running on Mono/.NET 4.5 (I've used VMWare Player 12.5.9 to run an openSUSE 13.3 64 Bit with 4GB RAM and 2 cores on an Intel(R) Core(TM) i7-5600U CPU):
How it looks running on .NET Framework 4.6.1 (I've used the same Intel(R) Core(TM) i7-5600U CPU):
How it looks running on .NET Core 2.1 (I've used the same Intel(R) Core(TM) i7-5600U CPU):
- Mono/.NET4.5 is the slowest environment for large list. Loyc performs very well in this scenario and is a good alternative.
- .NET Core 2.1 outperforms Loyc.
- .NET Framework 4.6.1 is better than Mono/.NET4.5 and worse than .NET Core 2.1. Loyc performs very well in this scenario and is a good alternative.
- 11th February, 2019: Initial version