Advertisement
Guest User

Untitled

a guest
Mar 4th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1.         private static void Main(string[] args)
  2.         {
  3.             const int globalRuns = 10;
  4.             const int localRuns = 1000;
  5.  
  6.             var source = Enumerable.Range(1, 200000).OrderBy(n => Guid.NewGuid()).ToArray();
  7.             var a = new int[source.Length];
  8.  
  9.             int start, end, total;
  10.  
  11.             for (int z = 0; z < globalRuns; z++)
  12.             {
  13.                 Console.WriteLine("Run #{0}", z+1);
  14.  
  15.                 total = 0;
  16.                 for (int i = 0; i < localRuns; i++)
  17.                 {
  18.                     Array.Copy(source, a, source.Length);
  19.                     start = Environment.TickCount;
  20.                     Array.Sort(a);
  21.                     end = Environment.TickCount;
  22.                     total += end - start;
  23.                 }
  24.                 Console.WriteLine("{0}\t\tTtl: {1}ms\tAvg: {2}ms", ".NET", total, total / localRuns);
  25.  
  26.                 total = 0;
  27.                 for (int i = 0; i < localRuns; i++)
  28.                 {
  29.                     Array.Copy(source, a, source.Length);
  30.                     start = Environment.TickCount;
  31.                     Quicksort.Sort(a);
  32.                     end = Environment.TickCount;
  33.                     total += end - start;
  34.                 }
  35.                 Console.WriteLine("{0}\t\tTtl: {1}ms\tAvg: {2}ms", "Inlined", total, total / localRuns);
  36.  
  37.                 total = 0;
  38.                 for (int i = 0; i < localRuns; i++)
  39.                 {
  40.                     Array.Copy(source, a, source.Length);
  41.                     start = Environment.TickCount;
  42.                     Quicksort.Sort2(a);
  43.                     end = Environment.TickCount;
  44.                     total += end - start;
  45.                 }
  46.                 Console.WriteLine("{0}\tTtl: {1}ms\tAvg: {2}ms\n", "Not inlined", total, total / localRuns);
  47.             }
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement