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

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

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 preproduced in any way without express permission from David McCarter.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.