fork(2) download
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. int a = 1, b = 5, c = 3;
  10. var arr = new[] { a, b, c };
  11. int[] ints = { a, b, c };
  12. var sw = new Stopwatch();
  13.  
  14. sw.Start();
  15. Array.Sort(arr);
  16. Array.Reverse(arr);
  17. Console.WriteLine("{0}, {1}, {2}", arr[0], arr[1], arr[2]);
  18. sw.Stop();
  19.  
  20. Console.WriteLine("Took {0} Ticks...", sw.ElapsedTicks);
  21. sw.Reset();
  22.  
  23. arr = new[] { a, b, c };
  24.  
  25. sw.Start();
  26. Array.Sort(arr, new Comparison<int>((x, y) => y.CompareTo(x)));
  27. Console.WriteLine("{0}, {1}, {2}", arr[0], arr[1], arr[2]);
  28. sw.Stop();
  29. Console.WriteLine("Took {0} Ticks...", sw.ElapsedTicks);
  30.  
  31. sw.Start();
  32. string ordered = string.Join(",", ints.OrderByDescending(i => i));
  33. Console.WriteLine(ordered);
  34. sw.Stop();
  35. Console.WriteLine("Took {0} Ticks...", sw.ElapsedTicks);
  36. }
  37. }
Success #stdin #stdout 0.06s 24464KB
stdin
Standard input is empty
stdout
5, 3, 1
Took 321222 Ticks...
5, 3, 1
Took 10653 Ticks...
5,3,1
Took 196475 Ticks...