I would like to know what is better to use.
IComparer class and Compare method for sort or LINQ orderby on List. Both works fine but which one is better for large lists.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would choose LINQ for two reasons.
I would expect performance to be roughly similar for a single-threaded implementation, if you consider that the lambda expression in your OrderBy clause compiles to a function — which is pretty much all you get by implementing IComparer anyway.
That being said, you might get more of a performance boost by changing your sort algorithm to be tailored to how your data is already sorted, rather than by changing your comparison method. But I’d be willing to bet my coffee this morning that OrderBy in your Linq statements uses an implementation of Quicksort, so it’s probably pretty decent in the general case already.