I have an array of structs and I need to locate all the elements that share a certain condition.
Currently I use:
Array.FindAll(someArray, x => x.eg == "*Perfomance Test*")
But after some googling I noticed that there is a much faster way by using the LINQ Where
-method.
someArray.Where(x => x.eg == "*Perfomance Test*")
I did some testing and the results are pretty impressive:
FindAll
: 00:00:03.06Where
: 00:00:00.20
The problem is that Where
returns IEnumerable
. And I call this method that returns all these certain elements from the array within the for loop. Which is the type of loop I need to use. I used the .ToArray()
method, but that made it much worse so that FindAll()
is the faster approach.
Because of that it seems to me that if I need to get an array of elements, Where
is much slower option than FindAll
. But maybe I'm missing something.
Are there any better, faster options?