Collection Performance: Finding First or Last and Count

Many developers use LINQ methods such as First(), Last(), and Count() to interact with collections. However, these methods can be about 2.33× slower in performance compared to direct indexing. Caution is advised when using indexing to avoid exceptions, and consideration should be given to code readability versus performance.

Collection Performance: Harnessing AsSpan() for Byte Array Conversion

When working with byte arrays, converting to Span can be achieved through AsSpan(). This method offers performance optimization by providing direct access without creating new arrays, efficient memory management, improved code clarity, and future-proofing for .NET framework evolution. Benchmark results show AsSpan() to be twice as performant with minimal memory allocations.

Collection Performance: Adding Items To a Dictionary

The excerpt from "Rock Your Code" discusses two methods for adding items to a Dictionary in .NET: Add() and TryAdd().

Collection Performance: The Fastest Way To Iterate Over a Collection in .NET!

Discover the quickest method to iterate over a collection in Microsoft.NET with this article, which includes performance benchmark tests.

256 Seconds with dotNetDave: Be careful using ContainsKey() with Dictionary Types

In this episode, I will demonstrate the issues associated with using `ContainsKey()` with Dictionary types in Microsoft .NET, which can potentially lead to performance problems. Updated September 2023.

Collection Performance: Processing Collections with Parallel.For() and Parallel.ForEach()

Since .NET 4.0, under the System.Threading.Tasks namespace, processing of collections can be sped up by using Parallel.For() and Parallel.ForEach(). These methods operate with thread-local data that runs in parallel. Both are easy to use and come with different options. This article shows you how to use these methods along with benchmark results.

Collection Performance: Creating Immutable Sorted Collections

ImmutableSortedDictionary and ImmutableSortedSet are available as immutable sorted collections. Performance benchmarks reveal that ImmutableSortedSet outperforms ImmutableSortedDictionary in both scenarios. Using CreateRange() is more efficient than CreateBuilder() with foreach(). However, employing a List with the Sort() method proves to be the most efficient option.

Collection Performance: Sorting With LINQ

There are several ways to sort a collection in .NET and one of them is by using LINQ. Two main extension methods are part of LINQ that can be used to easily sort collections.

Internationalization and Localization Performance: Collection Count() & Any() with Predicate

In this article, I will show you how to properly use Any() or Count() with collections taking globalization into account. Updated February 2023.

Collection Performance: A Comprehensive Benchmark Analysis of Collection Types in .NET Beyond Arrays and Lists

This article conducts a comprehensive benchmark analysis of various collection types in .NET beyond arrays and lists. It explores the performance of iteration methods, revealing significant differences among types, providing valuable insights for developers to choose the most performant collection type based on their code requirements.