The article explores the performance implications of using LINQ for collection queries, finding that a conventional foreach() loop outperforms LINQ by 1.75 times in identifying items matching a given query. The conclusion suggests benchmarking to determine the optimal approach based on the nature of the query and elements being sought.
Tag: Collections
Collection Performance: Creating a List<> Using The Task.Parallel Library
The post discusses alternative approaches to adding items to a collection using For() or ForEach() from the Task Parallel Library.
General Performance: Optimizing Method Returns
Modern best practices in method design emphasize returning empty collections instead of null values when no items are found, enhancing code safety and clarity.
Collection Performance: Comparing Key Search Methods in Dictionaries
The post discusses two methods for searching a specific key in a Dictionary. The ContainsKey() method is recommended by Microsoft for improved performance but is it more performant?
Collection Performance: Using ForEachAsync() with List<>
The post demonstrates the usage of Parallel.ForEachAsync() with a List of reference types.
Collection Performance: Comparing Byte Array’s with SequenceEqual()
LINQ's SequenceEqual() method compares two Byte arrays, returning a Boolean indicating equal length and matching elements. Access more on collection performance by subscribing.
Speed up LINQ Any() with Spargine FastAny()
The article introduces FastAny(), a method in the DotNetTips.Spargine.Extensions NuGet package designed to accelerate LINQ's Any() call, showcasing a 1.08 times performance improvement over the standard method. Notably, FastAny() not only enhances speed but also includes a built-in null check for the collection.
Collection Performance: Comparing ImmutableArray<>’s with SequenceEqual()
The ImmutableArrayExtensions contain a SequenceEqual() method for comparing ImmutableArray items. The method compares elements using the default equality comparer for TSource and can be used with a for() loop for performance validation.
Collection Performance: Iterating Through Reference Value, and Record Types
The author delves into the performance disparities of using reference types, value types, and record types in collections.
Collection Expressions in .NET 8
Beginning with .NET 8, you have the option to employ the novel collection expression to generate frequently used collection values. A collection expression comprises a concise syntax, which, upon evaluation, can be assigned to a wide array of collection types. Key Features of Collection Expressions: Concise Syntax: Easily create collections using square brackets [] and comma-separated elements, such as … Continue reading Collection Expressions in .NET 8

You must be logged in to post a comment.