One day i sat on researching what might be the fastest way to search for a particular... object in a List<T>....
The Searching Techniques i used....
was.....
For Loop
For Each Loop
While Loop
List<T>.Contain s //no intension retrieve index but only for checking
List<T>.Find Index // using Predicate
List<T>.FindInd ex ///using Lambda Expressions.
LINQ
I filled a List of type Rectangle..... will 10.6 million Rectangle objects....
and then searched for a known rectangle object and here are the results
For Loop 552 milliseconds
For Each 610 milliseconds
While Loop 594 milliseconds
List<T>.Contain s 203 milliseconds
List<T>.Find Index(Predicate ) 219 milliseconds
List<T>.FindInd ex(Lambda) 172 milliseconds
LINQ 781 milliseconds
and the award goes to List<T>.FindInd ex with Lambda Expressions...
LINQ happens to the most slowest and FindIndex with Lambda Expressions is the most fastest....
check it out.....
this test was done on a
Core2Duo 2.00 Ghz .... 2GB RAM machine
The Searching Techniques i used....
was.....
For Loop
For Each Loop
While Loop
List<T>.Contain s //no intension retrieve index but only for checking
List<T>.Find Index // using Predicate
List<T>.FindInd ex ///using Lambda Expressions.
LINQ
I filled a List of type Rectangle..... will 10.6 million Rectangle objects....
and then searched for a known rectangle object and here are the results
For Loop 552 milliseconds
For Each 610 milliseconds
While Loop 594 milliseconds
List<T>.Contain s 203 milliseconds
List<T>.Find Index(Predicate ) 219 milliseconds
List<T>.FindInd ex(Lambda) 172 milliseconds
LINQ 781 milliseconds
and the award goes to List<T>.FindInd ex with Lambda Expressions...
LINQ happens to the most slowest and FindIndex with Lambda Expressions is the most fastest....
check it out.....
this test was done on a
Core2Duo 2.00 Ghz .... 2GB RAM machine
Comment