linq orderby.tolist() performance

13,752

First of all, try to sort the list once, and keep it sorted.

To speed up things you can use Parallel LINQ.

see: http://msdn.microsoft.com/en-us/magazine/cc163329.aspx

An OrderBy() Parallel looks like this:

 var query = data.AsParallel().Where(x => p(x)).Orderby(x => k(x)).ToList();
Share:
13,752
Baran
Author by

Baran

Industrial Engineer

Updated on June 04, 2022

Comments

  • Baran
    Baran almost 2 years

    I have an ordering query to a List and calling for many times. list = list.OrderBy().ToList(); In this code ToList() method is spending high resources and takes very long time. How can I speed up with another ordering method without converting back to a list. Should I use .Sort extension for arrays?

  • Baran
    Baran about 13 years
    Ordering for one time is very fast but calling again and again makes it slow. I think in this situation using parallel makes it more slower. But thanks for your answer.