I can sort a list using Sort or OrderBy. Which one is faster? Are both working on same algorithm?
List<Person> persons = new List<Person>();
persons.Add(new Person("P005","Janson"));
persons.Add(new Person("P002","Aravind"));
persons.Add(new Person("P007","Kazhal"));
1.
persons.Sort((p1,p2)=>string.Compare(p1.Name,p2.Name,true));
2.
var query = persons.OrderBy(n => n.Name, new NameComparer());
class NameComparer : IComparer<string>
{
public int Compare(string x,string y)
{
return string.Compare(x, y, true);
}
}
Pravesh Singh
04-Feb-2014On my computer when compiled in Release mode this program prints:
Sort: 1162ms
OrderBy: 1269ms