Guest User

Untitled

a guest
Jun 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. private static void Main(string[] args)
  2. {
  3. int defaultN = 1000;
  4.  
  5. Stopwatch sw = new Stopwatch();
  6.  
  7. while (true)
  8. {
  9. Console.WriteLine("Enter test elements number:");
  10. int n;
  11. if (!int.TryParse(Console.ReadLine(), out n)) n = defaultN;
  12. else defaultN = n;
  13.  
  14. Console.WriteLine($"Test with {n} elements");
  15.  
  16. List<object> list = Enumerable.Repeat(new object(), n).ToList();
  17. sw.Start();
  18. Clear(list);
  19. sw.Stop();
  20. Console.WriteLine("Clear: {0} ms", sw.ElapsedTicks / 10000D);
  21.  
  22. GC.Collect();
  23. GC.WaitForPendingFinalizers();
  24.  
  25. List<object> list2 = Enumerable.Repeat(new object(), n).ToList();
  26. sw.Restart();
  27. Reinitialize(list2);
  28. sw.Stop();
  29. Console.WriteLine("Reinitialize: {0} ms", sw.ElapsedTicks / 10000D);
  30.  
  31. GC.Collect();
  32. GC.WaitForPendingFinalizers();
  33.  
  34. List<object> list3 = Enumerable.Repeat(new object(), n).ToList();
  35. sw.Restart();
  36. ReinitializeAndCollect(list3);
  37. sw.Stop();
  38. Console.WriteLine("ReinitializeAndCollect: {0} ms", sw.ElapsedTicks / 10000D);
  39.  
  40. Console.WriteLine("===");
  41. }
  42. }
  43. private static List<object> Clear(List<object> list)
  44. {
  45. list.Clear();
  46. return list;
  47. }
  48. private static List<object> Reinitialize(List<object> list) => new List<object>();
  49. private static List<object> ReinitializeAndCollect(List<object> list)
  50. {
  51. list = new List<object>();
  52.  
  53. GC.Collect();
  54. GC.WaitForPendingFinalizers();
  55.  
  56. return list;
  57. }
  58.  
  59. chart = new ChartistChart() { Title = "My fancy chart" };
  60. series = new List<ChartistMetaValue>();
  61. *some code for getting the statistics*
  62. chart.Series.Add(series);
  63. chartistLineCharts.Add(chart);
  64.  
  65. chart = new ChartistChart() { Title = "My second fancy chart" };
  66. series = new List<ChartistMetaValue>();
  67. *some code for getting the statistics*
  68. chart.Series.Add(series);
  69. chartistLineCharts.Add(chart);
  70.  
  71. series.Clear();
Add Comment
Please, Sign In to add comment