Collection Performance: Adding Items to a Collection

The most popular way to add an item to a collection is by using Add(). The other way is by using Insert() or Prepend(). This article shows performance results for these three methods.

Collection Performance: Looping Over Reference Type vs. Value Type

Since most of the types and collections I create are typically business objects, I wondered if collections of simpler types would be faster. I decided to benchmark the difference between a List (reference type) with a List (value type).

Collection Performance: Looping Over Collection – Array vs. List

The benchmarks in the book compared iterating over an Array and a List collection of reference types using for() and foreach(). The results showed that utilizing an array is 7.5 times faster, highlighting the performance advantage of using arrays for iteration.

Collection Performance: Sorting the Record Type

This article shows the difference between sorting a normal class type with a record class type.

Collection Performance: Sorting Collections

There are several ways to sort a collection in .NET. Some of the sorting methods are part of LINQ. Let’s look at the methods that are part of the System.Collections.Generic namespace.

Collection Performance: Looping Over Other Collection Types

This article shows benchmark results for adding items to a List collection by using AddRange() and for().

Collection Performance: Efficiently Checking for Items in a Collection

Before processing collections, always perform null and item checks. For counting items, prefer Count for speed, as it's more efficient than LongCount() and TryGetNonEnumeratedCount(). When working with arrays, use Length or LongLength instead of Count. Benchmarking is crucial for optimizing collection methods in .NET applications.

Collection Performance: Converting A List To Different Collection Types

What if you already have a collection in memory, like after calling a service or database, and you need to return it as a different collection type? This article will show you benchmark results when converting from a List.

Collection Performance: Creating New Sorted Collection From a Collection

This article talks about sorting collections with LINQ and doing the same using one of the sorted collections.

Collection Performance: Creating New Immutable Collection From a Collection

Immutable collections, which are collections that cannot be changed, was introduced in .NET 4.5 and are supported in .NET Core and beyond. There are immutable collections that mirror many of the generic collections in .NET. This article shows performance results from creating these types of collections.