C# Which is faster .Any() .Contains() or .Exists()

Started by Mr. Analog, December 14, 2016, 03:03:01 PM

Previous topic - Next topic

Mr. Analog

The answer was surprising:
http://stackoverflow.com/a/18651941

***************************************
***** ContainsExistsAnyShortRange *****
***************************************
List/Contains: 96ms
List/Exists: 146ms
List/Any: 381ms
Array/Contains: 34ms
Arrays do not have Exists
Array/Any: 410ms
***************************************
********* ContainsExistsAny ***********
***************************************
List/Contains: 257,996ms
List/Exists: 379,951ms
List/Any: 884,853ms
Array/Contains: 72,486ms
Arrays do not have Exists
Array/Any: 1,013,303ms
By Grabthar's Hammer

Melbosa

Sometimes I Think Before I Type... Sometimes!

Mr. Analog

It's surprising how costly .Any is, I never would have thought of it at all if I hadn't been looking for more performative ways of filtering lists in C#

Linq: Best friend AND worst enemy
By Grabthar's Hammer