// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; namespace E { public class Program { public const int N = 10000000; public const int M = 10; public static readonly Random rng = new Random(); public static void Main(string[] args) { List lst = new List(); for(int j = 0; j < M; j++) { lst.Add(new String('a', 1 + rng.Next(M))); } long t1 = DateTime.Now.Ticks; for(int i = 0; i < N; i++) { List lst2 = new List(lst); lst2.Sort((s1, s2) => s2.Length - s1.Length); } long t2 = DateTime.Now.Ticks; Console.WriteLine(t2 - t1); long t3 = DateTime.Now.Ticks; for(int i = 0; i < N; i++) { List lst2 = lst.OrderByDescending(s => s.Length).ToList(); } long t4 = DateTime.Now.Ticks; Console.WriteLine(t4 - t3); } } }