Advertisement
Guest User

GC Worse Case

a guest
Sep 20th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. class MyCls
  2. {
  3.     public int Data;
  4. }
  5.  
  6. class Program
  7. {
  8.     const int m_ArrSize = 299999999;
  9.     //const int m_ArrSize = 50000000;
  10.  
  11.     static long GetTickMS()
  12.     {
  13.         return DateTime.Now.Ticks / 10000;
  14.     }
  15.  
  16.     static void Main(string[] args)
  17.     {
  18.         Console.WriteLine("Start");
  19.         Random random = new Random();
  20.  
  21.         MyCls[] arr = new MyCls[m_ArrSize];
  22.  
  23.         long maxDelay = 0;
  24.         long startTick = GetTickMS();
  25.         long level = 100;
  26.  
  27.         for (; ; )
  28.         {
  29.             int[] pos = new int[] { random.Next(m_ArrSize), random.Next(m_ArrSize), random.Next(m_ArrSize) };
  30.  
  31.             for (int i = 0; i < 3; i++)
  32.             {
  33.                 int idx = random.Next(3);
  34.                 arr[pos[idx]] = new MyCls();
  35.             }
  36.  
  37.             for (int idx = 0; idx < 3; idx++)
  38.                 arr[pos[idx]] = null;
  39.  
  40.             long delayTick = GetTickMS() - startTick;
  41.             maxDelay = Math.Max(maxDelay, delayTick);
  42.  
  43.             if (maxDelay > level)
  44.             {
  45.                 Console.WriteLine("GC Pause Delay: {0}MS, level: {1}", maxDelay, level);
  46.                 level += 100;
  47.             }
  48.  
  49.             startTick = GetTickMS();
  50.         }
  51.         Console.ReadKey();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement