Speed up LINQ Any() with Spargine FastAny()

To enhance the performance of the Any() call in LINQ, I’ve introduced the FastAny() method within the DotNetTips.Spargine.Extensions NuGet package. Employing it is as straightforward as using the Any() call with a predicate:

var result = people.FastAny(p => p.FirstName.Equals(firstName));

Benchmark Results

As indicated by the benchmark, FastAny() from Spargine exhibits a 1.08 times improvement in performance. Additionally, this method incorporates a null check for the collection.

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be reproduced in any way without express permission from David McCarter.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.